1. (True/False) A sequence of 0s and 1s is called a decimal code.

2. (True/False) Secondary storage permanently stores data.

3. (True/False) The member functions of a class must be public.

4. (Multiple choice) Given the following class definition:

class employee {
public:
employee();
employee(string, int double);
employee(int, double);
employee(string);
};

and this statement:

employee newEmployee("Harry Miller", 0, 25000); // variable declaration

Which constructor is executed for the above variable declaration?

A. employee();
B. employee(string, int double);
C. employee(int, double);
D. employee(string);

5. (Multiple choice) Given this set of code:

class temporary {
public:
void set(string, double, double);
void print();
double manipulate();
void get();

private:
string description;
double first;
double second;
};

temporary temp;

Which of the following statements correctly calls the set method?

A. set("howdy", 1.0, 2.0);
B. temporary.set("howdy", 1.0, 2.0);
C. temp.set("howdy", 1.0, 2.0);
D. temporary->temp.set();

6. (True/False) The constructor of a derived class can specify a call to the constructor of the base class in the heading of the function definition.

7. (True/False) When diagramming the inheritance relationship between the base class and the derived classes, we usually put the base class on the bottom (base) and the derived classes above the base.

8. (True/False) The following is syntactically valid and makes semantic sense when deriving an employeeType class from the base class personType:

class employeeType: public personType {
public:
void setInfo(string, string, string, double, string, string);
void setSalary(double);
void setDepartment(string);
void setCategory(string);
void setID(string);
double getSalary() const;
string getDepartment(string) const;
string getCategory() const;
string getID() const;

private:
string department;
double salary;
string employeeCategory;
string employeeID;
};

9. (Fill in the blank(s)) Given the following:

class molecules: atom {
...
};

The base class is __________ and the derived class is __________.

10. (Multiple choice) Given:

class circle {
public:
void print() const;
void setRadius(double);
void setCenter(double, double);

private:
double xCoordinate;
double yCoordinate;
};

class cylinder: public circle {
public:
void print() const;
double volume;

private:
double height;
};

cylinder newCylinder;

What are the private members of newCylinder?

A. height
B. height
xCoordinate
yCoordinate
C. xCoordinate
yCoordinate
D. newCylinder has no private members because it is declared using the public access modifier.

11. (True/False) In C++, there is no difference between a reserved word and a predefined identifier.

12. (Multiple choice) Which of the following are valid C++ identifiers?

A. firstCPPProject
B. POP_QUIZ
C. C++Program2
D. myHomWorc

13. (Multiple choice) Which of the following is/are reserved word(s) in C++?

A. const
B. include
C. char
D. void
E. int
F. return

14. (True/False) A keyword is a reserved word defined by the system. A keyword cannot be redefined in a program.

15. (True/False) The identifiers firstName and FirstName are interchangeable in a program.

16. (Multiple choice) Which header file must be included to use the function pow?

A. Iostream
B. matlab
C. mathio
D. cmath

17. (True/False) Given the appropriate includes, the following statement will write out 35 contiguous characters:

cout << setfill('*') << setw(35) << '*' << endl;

18. (True/False) Assuming appropriate includes and given the following statements:

int age;
char ch;
string name;
cin >> age;
cin.get(ch);
getline(cin, name);

and provided the following one line of input:

23 Lance Grant

The value of age will be 23 and the value of name will be "Lance".

19. (Multiple choice) An input stream may enter the fail state when:

A. a user takes too long to enter data
B. the program expected upper case letters, but lower case letters were entered
C. invalid data was entered
D. there are spaces in the input for a string variable

20. (Fill in the blank) Output for the following program is __________.

#include < iostream >
#include < cmath >
using namespace std;
int main() {
int x = 4;
int y = 3;
cout << static_cast< int >(pow(x, 2.0)) << endl;
};

21. (True/False) The result of a logical expression cannot be assigned to an int variable.

22. (Multiple choice) Which of the following are relational operators?

A. <
B. <=
C. =
D. !=

23. (Multiple choice) Which of the following are logical (Boolean) operators?

A. !
B. !=
C. All of the above
D. None of the above

24. (Multiple choice) Given the following code, what is the value of shippingCharges if numOfItemsBought = 6 after the statements have completed executing?

if(0 < numOfItemsBought || numOfItemsBought != 5)
shippingCharges = 5.00 * numOfItemsBought;
else if(5 < numOfItemsBought && numOfItemsBought < 10)
shippingCharges = 2.00 * numOfItemsBought;
else
shippingCharges = 0.00
A. 0.00
B. 12.0
C. 30.0
D. None of the above

25. (Fill in the blank) The output from the following statement is __________.

if('4' > '3' || 2 < -10)
cout << "1 2 3 4";
cout << "$$";

26. (True/False) In a while loop controlled by a counter, it is not necessary to initialize the counter variable.

27. (Multiple choice) The following code is supposed to read in 20 numbers and find the sum. There is a defect in the code and you need to choose the option that will correct the defect.

int count = 0; // Line 1
int sum = 0; // Line 2
cin >> num; // Line 3
while(count < 20) // Line 4
{
cin >> num; // Line 5
count++; // Line 6
sum = sum + count; // Line 7
}
A. Change Line 1 to the following: count = 1;
B. Change Line 3 to the following: cin >> sum;
C. Change Line 4 to the following: while(count < 20)
D. Change Line 7 to the following: sum = sum + num;

28. (Multiple choice) The condition for this while loop is supposed to check the input variable called response to see if it is equal Y or y. Choose the appropriate option below so that it works properly.

while( response == 'Y' && response == 'y')
A. while(response = 'Y' && response = 'y')
B. while(response == 'Y' & response = 'y')
C. while(response == 'Y' | response == 'y')
D. while(response == 'Y' || response == 'y')

29. (True/False) The following two code sets produce the same output.

Code set 1:

int limit = 4;
int first = 5;
int j;
for(j=1; j <= limit; j++) {
cout << first * j << endl;
first = first + (j - 1);
}
cout << endl;

Code set 2:

int limit = 4;
int first = 5;
int j;
j = 1;
do {
cout << first * j << endl;
first = first + (j - 1);
j++;
}
while(j <= limit);
cout << endl;

30. (Multiple choice) What is the output of the following code?

int i, j;
for(i=1; i<=5; j++)
cout << setw(5) << j;
cout << endl;
}
A. 2 3 4 5
B. 3 4 5
C. 4 5
D. 5
E. 1
F. 1 2
G. 1 2 3
H. 1 2 3 4
I. 1 2 3 4 5
J. None of the above

31. (Multiple choice) What does a break statement do in a loop?

A. Terminates the loop immediately
B. Pauses execution for 10 milliseconds and then continues execution
C. Skips one iteration of the loop
D. None of the above

32. (True/False) The continue statement exits a loop structure and allows the program to continue with the first statement immediately following the loop statement.

33. (True/False) Parameters allow you to use different values each time the function is called.

34. (Multiple choice) Consider the following function definition:

int func(int x, double y, char u, string name) {
// function body
}

Which of the following are correct function prototypes of the function func?

A. int func(x, y, u, name);
B. int func(int s, double k, char ch, string name);
C. int func(int, double, char, string);
D. func(int, double, char, string);

35. (Multiple choice) Consider the following statements:

int num1=6, num2=7, num3=4;
double length=6.2, width=2.3, height=3.4;
double volume;

And the function prototype:

double box(double, double, double);

Which of the following statements are valid?

A. volume = box(length, width, height);
B. volume = box(length + width, height);
C. cout << box(6.2, , height) << endl;
D. cout << box(num1, num3, num2); << endl;

36. (Multiple choice) Given the following:

int func1(int, double);

Which of the following is/are correct statement(s)?

A. cout << int func1(2, 4.0);
B. cout << func1( ,2.0);
C. cout << func1(1, 2.0);
D. None of the above

37. (True/False) In a program with many user defined functions and main being the first implemented user defined function all other user defined functions must have a prototype appearing before main.

38. (True/False) The output of the following code is the sum of integers between 1 and 100 whose square roots are also integers.

int temp = 0;
for(int counter = 1; counter <= 100; counter++)
if(pow(floor(sqrt(counter / 1.0)), 2.0) == counter)
temp = temp + counter;
cout << temp << endl;

39. (True/False) A function can return a value of an enumeration type.

40. (Multiple choice) Given:

enum currencyType {DOLLAR, PUND, FRANK, LIRA, MARK};
currencyType currency;

Which of the following statements are valid?

A. currency = DOLLAR;
B. cin >> currency;
C. currency = static_cast< currencyType >(currency + 1);
D. for(currency = DOLLAR; currency <= MARK; currency++) cout << "*";

41. (True/False) Given:

enum courseType {ALGEBRA, ASTRONOMY, PHYSICS};
courseType course;

The following retrieves and then outputs the course entered by a user.

42. (Multiple choice) Given:

enum courseType {ALGEBRA, ASTRONOMY, PHYSICS};

We are asked to define a function header for a function that will read in a course and return the courseType. Which function prototype below is correct?

A. string readIn();
B. courseType readIn();
C. int readIn();
D. None of the above

43. (True/False) Because there is no name for an anonymous type, you cannot pass an anonymous type as a parameter to a function.

44. (True/False) Arrays can be passed as parameters to a function either by value or by reference.

45. (True/False) The following is a valid array declaration with 80 integer elements:

int age[0..79];

46. (True/False) The following is a valid sequence of statements:

int SIZE;
double list[SIZE];

47. (Multiple choice) What is the valid range of array index values for the following declaration?

const MAX = 64;
int scores[MAX];
A. 1 to 64;
B. 0 to 64;
C. 1 to 63;
D. None of the above

48. (True/False) Given the following statements:

int n = 5;
int m = 60;
int list[100];
list[55] = 235;

This is a legal and valid statement:

list[50] = list[m - n];

49. (True/False) The following code is valid:

struct timeType {
int hr;
double min;
int sec;
};

struct tourType {
string cityName;
int distance;
timeType duration;
};

tourType destination;
destination.cityName = "Rome";
destination.hr = 4;

50. (True/False) Using the nameType from a previous exercise and given the following:

struct employeeType {
nameType name;
int performanceRating;
int pID;
string dept;
double salary;
};

employeeType employees[100];
employeeType newEmployee;

This is a valid statement:

employees.salary = 41000;
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.