473,397 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

help me to test how can more simple for this C++ answer

Q:Write a program that prints the numbers 1 to 4 on the same line with
with each pair of adjacent numbers separated by one space. Do this
several ways:
a) Using one statement with one stream insertion operator.
b) Using one statement with four stream insertion operators.
c) Using for statement

my answers are as follow

a)
{
std::cout << "1 2 3 4";
system("PAUSE");
return 0;
}

b)
{
std::cout << "1" << " 2" << " 3" << " 4";
system("PAUSE");
return 0;
}

c)
{
std::cout << "1";
cout << " 2";
cout << " 3";
cout << " 4";
system("PAUSE");
return 0;
}
i don't know this answer is right or not
if right
how can be more simple for this question?

Oct 23 '06 #1
4 3269
<al**************@gmail.comwrote in message
news:11*********************@f16g2000cwb.googlegro ups.com
Q:Write a program that prints the numbers 1 to 4 on the same line with
with each pair of adjacent numbers separated by one space. Do this
several ways:
a) Using one statement with one stream insertion operator.
b) Using one statement with four stream insertion operators.
c) Using for statement

my answers are as follow

a)
{
std::cout << "1 2 3 4";
system("PAUSE");
return 0;
}

b)
{
std::cout << "1" << " 2" << " 3" << " 4";
system("PAUSE");
return 0;
}

c)
{
std::cout << "1";
cout << " 2";
cout << " 3";
cout << " 4";
system("PAUSE");
return 0;
}
i don't know this answer is right or not
if right
how can be more simple for this question?
a) and b) are fine. c) does not use a for statement, so is incorrect.
--
John Carson
Oct 23 '06 #2

al**************@gmail.com wrote:
c)
{
std::cout << "1";
cout << " 2";
cout << " 3";
cout << " 4";
system("PAUSE");
return 0;
}
i don't know this answer is right or not
if right
how can be more simple for this question?
Question 3 may be implemented use ostream_iterator<intlike this:
#include<iostream>
#include<iterator>
using namespace std;
int main()
{
ostream_iterator<intnumOut(cout);
ostream_iterator<charspaceOut(cout);
int a[]={1,2,3,4};
for(int i=0;i<4;i++){
numOut++=a[i];
spaceOut++=' ';
}
}

Oct 23 '06 #3
al**************@gmail.com wrote:
Q:Write a program that prints the numbers 1 to 4 on the same line with
with each pair of adjacent numbers separated by one space. Do this
several ways:
a) Using one statement with one stream insertion operator.
b) Using one statement with four stream insertion operators.
c) Using for statement

my answers are as follow

a)
{
std::cout << "1 2 3 4";
system("PAUSE");
return 0;
}

b)
{
std::cout << "1" << " 2" << " 3" << " 4";
system("PAUSE");
return 0;
}

c)
{
std::cout << "1";
cout << " 2";
cout << " 3";
cout << " 4";
system("PAUSE");
return 0;
}
i don't know this answer is right or not
if right
how can be more simple for this question?
None of your answers are correct, since none of them are programs.

You are missing main, you are missing the necessary #includes for
std::cout and operator<<(std::ostream&,const char *).

In addition, I believe (but I can't find chapter&verse) that if you
don't flush/endl an ostream, your output is undefined -- you may not see
anything.
Oct 23 '06 #4
<al**************@gmail.comwrote in message
news:11*********************@f16g2000cwb.googlegro ups.com...
Q:Write a program that prints the numbers 1 to 4 on the same line with
with each pair of adjacent numbers separated by one space. Do this
several ways:
a) Using one statement with one stream insertion operator.
b) Using one statement with four stream insertion operators.
c) Using for statement

my answers are as follow

a)
{
std::cout << "1 2 3 4";
system("PAUSE");
return 0;
}
Fine
b)
{
std::cout << "1" << " 2" << " 3" << " 4";
system("PAUSE");
return 0;
}
Fine.
c)
{
std::cout << "1";
cout << " 2";
cout << " 3";
cout << " 4";
system("PAUSE");
return 0;
}
Nope. Don't see a for statement here.

for ( int i = 1; i <= 4; ++i )
// do your std::cout << here
i don't know this answer is right or not
if right
how can be more simple for this question?

Oct 23 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Weekend | last post by:
Currently, i want to develope a multiple choice exam website. The content of the test is store in an XML file. I want to carry out some function. Could you tell me which programming language should...
16
by: Simon | last post by:
I am a programming student and have recently missed two weeks of school due to a serious injury in a car accident. I am completing all of my assignments (via Labs) but have come across the...
3
by: SK | last post by:
I want to get multiple choice questions in the following areas. I do not expect respondents to be able to commit to providing questions in every area listed in this description. Typically I expect...
3
by: cc | last post by:
hi, how do I make keyboard & mouse temporary not response to desktop
36
by: felixnielsen | last post by:
What i really wanna do, is defining my own types, it doesnt really matter why. Anyway, i have run into some problems 1) typedef unsigned short U16; U16 test = 0xffffffff; // There should be a...
20
by: Mike | last post by:
Hi all, I am cramming for an technical interview about C++ and programming... I believe there will be problems on data-structures and algorithms... could anybody recommend some online...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
4
by: =?Utf-8?B?Z3Jhenph?= | last post by:
Hello If someone can help me with this it would be greatly appreciated. I’m no web service expert but I don't think i'm trying to do anything too special. I think i must be missing something...
1
by: kvazar | last post by:
What I am trying to create is basically a page with a bunch of multiple choice questions. Basically just like a test page. I am providing the code lower. All the questions that need to show as a part...
6
by: smk17 | last post by:
I've spent the last few minutes searching for this question and I found an answer, but it wasn't quite what the client wanted. I have a simple online form where the user needs to fill out five...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.