 |
 |
: -( Need help with C++ Programming questions
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Nov 2001
Location: 2166 Hone Ave.
Status:
Offline
|
|
I have to do this quiz over thanksgiving weekend for my c++ class, and its about controls and functions which is a topic the teacher has never gone over. Anyway I forgot to bring my book where I could read about this stuff, and I need to have this stuff done by Monday and well, any help would be appreciated. Below are the multiple choice questions.
1.Which of the following is a valid statement?
Your answer:
int gallons; liters;
char symbol = 'a';
int = 5;
for(int i = 0; i < 4; i- -)
------------------------------------------------------------------------
2.
What is printed by the following statements?
int c = 3;
c+=4; c -= 1; c *= 4;
cout << c << endl;
Your answer:
32
24
zero
12
------------------------------------------------------------------------
3. Which of the following is a true statement?
Your answer:
10/6 = 1
10%5 = 2
int is a valid variable
cin is the stream extraction operator
------------------------------------------------------------------------
4. Which of the following statements will cause the loop to iterate four (4) times?
Your answer:
for(int i = 0; i <=4; i++)
for(int i =0; i < 4; i- -)
for(int i = 4; i >0; i- -)
for(int i = 1; i <4; i++)
------------------------------------------------------------------------
5. The expression i++ is equivalent to:
Your answer:
i += i;
i %= 1;
i += 1;
++i;
------------------------------------------------------------------------
6. Given the statement: double x = 3.25, which of the following statements will cause the contents of the variable x to be printed as 3?
Your answer:
cout<<abs(x);
cout <<int(x);
cout <<x - 3;
cout <<char(x);
------------------------------------------------------------------------
7.
What is the output of the following code, if the user enters 3?
int dist;
cout <<"Enter travel distance in miles"
cin >> dist;
dist *= 1.6; cout "miles = " << double(dist) <<" km/hr"
Your answer:
4.0
4.8
3
4
------------------------------------------------------------------------
8. Which of the following code sequences will allow you to print the sequence: 3,8,13,18?
Your answer:
for(int i = 1; i <= 4; i ++)
cout<<setw(3)<<3*i;
for(int i = 0; i <= 3; i ++)
cout<<setw(3)<<i+;3;
for(int i = 3; i <= 18; i += 5)
cout<<setw(3)<<i;
for(int i = 0; i <= 18; i =i+5)
cout<<setw(3)<<i;
------------------------------------------------------------------------
9. Which of the following statements correctly matches implementation and prototype?
Your answer:
int Square();
int number = Square();
void square();
int number = square(5);
void square(int);
int number = square(5);
int square(int);
int number = square(5);
------------------------------------------------------------------------
10.
Supply the missing expression to create a loop that iterates five (5) times:
for(int i = 4;________;i--)
Your answer:
i <0;
i <=0;
i = 0
i >=0;
------------------------------------------------------------------------
11. If string s = "BABYLONIAN", then the statement cout<
Your answer:
the character N
Nothing. The method exceeds the length of the string.
the character B
Nothing. s.size() is undefined.
------------------------------------------------------------------------
12. Given s = "Happy Thanksgiving", which of the following statements would print THANKS to the screen?
Your answer:
cout << s.substr(5,6);
cout << s.substr(1,6);
cout << s.substr(6,6);
cout << s.substr(7,6);
------------------------------------------------------------------------
13. Which of the following C++ expressions has a value of 4?
Your answer:
3+1/3+2/3
2^2
16%4
9%4+12%9
------------------------------------------------------------------------
14. Which of the following include files would NOT be required to print a paragraph of text to the screen or to a file?
Your answer:
iomanip.h
iostream.h
ifstream.h
string.h
------------------------------------------------------------------------
15. In the function heading double Sum(int a,char b), a and b are called
Your answer:
declarations
parameters
implementations
arguments
------------------------------------------------------------------------
16.
Given the method:
int what(int n)
int number = n*(n+1);
return number;
}
If the statment number1 = what(number2) appears in the main function,
number2 is called a(n)_____ in this function call.
Your answer:
declaration
argument
parameter
value
------------------------------------------------------------------------
17. Assume you want to type your full name, first and last, into a string variable myName. Which of the following statements would you use?
Your answer:
cin>>myName;
cout<<myName;
getline(myName);
getline(cin.myName);
------------------------------------------------------------------------
18.
Which of the following lines identifies the number of coins
that are not quarters?
1. cin>>change;
2. int coins = change * 100;
3. int quarters = coins/25;
4. coins %= 25;
Your answer:
line 1
line 4
line 2
line 3
------------------------------------------------------------------------
19.
In the program segment
int x = 5;
void Fun()
{
int x = 2; x *= 2;
}
int main()
{
Fun();
cout<<
return 0;
}
What is the program output?
Your answer:
5
20
10
2
------------------------------------------------------------------------
20. When reading two characters using the input operator >>, it matters how many blanks appear
Your answer:
when printing to the screen.
before the first character.
after the second character.
between the first and second character.
Anyway thanks.
|
|
|
| |
|
|
|
 |
|
 |
|
Posting Junkie
Join Date: Jun 2001
Location: Washington DC
Status:
Offline
|
|
I don't get it, do you want us to tell you the answers? Most of them you could just try compiling and running to get the answers...
|
|
|
| |
|
|
|
 |
|
 |
|
Administrator 
Join Date: Mar 2000
Location: Land of the Easily Amused
Status:
Offline
|
|
moving to os x developer. maybe someone will do your homework for you there.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Jan 2000
Location: Chicago
Status:
Offline
|
|
My c++ is a bit rusty. Haven't touched it since I was in high school.
These questions aren't that hard though. I "sorta" know the answers to them, but I also don't feel like taking the time and effort to do your homework for you, and I also forgot some things, but I could probably relearn it fairly fast. Search around on the web. I'm sure you can find a tutorial that will replace your textbook.
Anyway, for question number one, the answer is not A since the line has 2 ';'
|
|
|
| |
|
|
|
 |
|
 |
|
Admin Emeritus 
Join Date: Oct 2000
Location: Boston, MA
Status:
Offline
|
|
Hmm, I can reference you to some books and sites, but doing your hw/quiz for you? 
|
|
"Against stupidity, the gods themselves contend in vain" (Schiller)
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Aug 2001
Location: Vienna, Austria
Status:
Offline
|
|
Originally posted by jarends:
<STRONG>Anyway, for question number one, the answer is not A since the line has 2 ';'</STRONG>
That's not correct, if liters was already defined before like here:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
int liters;
int gallons; liters;
</font>[/code]
It's valid, but "liters;" won't do anything (the result of the expression will be discarded).
Question #10 is totally bogus, there's no correct answer (since there's always one ";" too much).
Most of the questions can be solved by writing a simple C++-app or using bc (in Mac OS X's terminal).
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Oct 2000
Location: Los Angeles, CA
Status:
Offline
|
|
I would be willing to help you, but frankly I'm disappointed that you posted the entire homework online and expect someone to do it for you. Specific questions are fine, but why did you put the entire assignment up there? Do you not understand any C++? If that's your problem, no one on these boards can help you. I would suggest dropping the course or getting one-on-one instruction from someone capable in the language.
|
|
Fyre4ce
Let it burn.
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Dec 2000
Location: Edmonton, Canada
Status:
Offline
|
|
Originally posted by Max Patan:
<STRONG>Anyway I forgot to bring my book where I could read about this stuff, and I need to have this stuff done by Monday and well, any help would be appreciated. Below are the multiple choice questions.
</STRONG>
Sorry, don't have time to answer your quiz...but you may want to check out an online C book (I think the above is mostly plain C)
How about this site or this site.
[ 11-25-2001: Message edited by: MachoManRandySavage ]
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|