Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m working on a study guide for my C++ Programming Class final exam and need s

ID: 3581483 • Letter: I

Question

I'm working on a study guide for my C++ Programming Class final exam and need some help with these questions. I also don't have an answer key so I don't know if I am getting the study guide questions correct or not.

Multiple Choice:

1) What is wrong with the following function body?
void calculate(int count, float price, float& cost)
{
if (count < 0)
cost=0.0;
else
cost=count*price;
return;
}
a. void functions may not have a return statement.
b. void functions must return a value
8
c. nothing
d. cannot mix pass-by-reference and pass-by-value parameters

2) Which of the following declare an array of 5 characters, and initializes them to some known values?
a. char array[5]={'a','b','c','d','e'};
b. char array[4]={'a','b','c','d','e'};
c. char array[5]={''};
d. char array[]={'a','b','d','e'};
e. A and C
f. B and D
g. all of the above

3) Which of the following function declarations correctly expect an array as the first argument?
a. void f1(int array, int size);
b. void f1(int& array, int size);
c. void f1(int array[100], int size);
d. void f1(float array[], int size);
e. All of the above
f. C and D
g. A and B

4) The following function definition has an error in it. On what line is this error?
0. void f1(const double array[], int size)
1. {
2. int i=0;
3. while (i < size)
4. {
5. array[i] += 2;
6. cout << array[i];
7. i++;
8. }
9. }

a. 0
b. 2
c. 5
d. 6
e. 2

5)How can you assign the value "toaster" to a c-string name str of size 10?
a. str="toaster;
b. str=toaster;
c. strcpy(str,"toaster");
d. str.strcpy("toaster");

6) What is wrong with the following code fragment?
char str1[10]="Annie", str2[15]="What's my name";
strcpy(str1,str2);
a. Nothing
b. str2 has white space in it
c. str1 does not have enough room
d. str2 does not have enough room

7) What is the value of str after the following code?
string str;
a. a garbage string
b. the empty string
c. the null character
d. unknown

8) Which of the following would correctly read an entire line from an input file stream named fin into a string variable named line.
a. getline(fin, line);
b. fin.getline(line);
c. fin.getline(line,' ');
d. fin.getline(line,80);

9) Given the following code, what is the correct statement to insert the string str2 into str1, directly after the 'd'?
string str1="abcdefg";
string str2="ABCDE";
a. str1.insert(4,str2);
b. str2.insert(4,str1);
c. insert(str1,4)=str2;
d. insert(str2,4)=str1;

Explanation / Answer

1)ans)c

Actually there was no wrong with this function code.void function can use return statement,but should not return any value.

2)ans)a

3)ans)f

4)ans)c

Always we have to assign a value to a variable.

5)ans)C

6)ans)

7)Ans)b

It will not having anything.

7)ans)c

8)ans)a

9)ans)a