Spring 1995 MidSemester Exam (100pts) Name________________________ 1.(4pts) Does the following assignment always correctly store the average of the three int objects a, b, and c into ave _______? *** No float ave = (a+b+c/3.0); 2.(7pts) Circle only the valid identifiers that follow: main cin A 1a A_1 M/H coarse_describbles *** main cin A A_1 coarse_describbles 3. (8pts) Place circles for each error that would result in compiletime error #include > x; return 0; *** should be (with *** marking lines with errors): #include *** #include *** int main()*** { int x = 0;*** int j = 0;****** cout << "Hello" << j;*** cin >> x;*** return 0; }*** 4. (4pts) Write a single assignment statement that changes the value of cost by adding a 17.5% tax to cost. The increase must be correct for any initial value of cost, not just 100.00. float cost = 100.00; *** cost = 1.175*cost; or cost = cost + .175*cost; or cost *= 1.175; 5. (10pts) Write the output generated by the following program: #include #include "ouracct.h" // for class bankAccount int main() { bankAccount Kay("Missie", "9876", 100.00); cout << Kay.name() << " " << Kay.PIN() << endl; cout << Kay.balance() << endl; Kay.deposit(23.45); cout << Kay.balance() << endl; Kay.withdraw(50.00); cout << Kay.balance() << endl; return 0; } *** MISSIE 9876 100 123.45 73.45 6. (10pts) Complete this program that constructs one bankAccount object using any data you desire. Then make a deposit of 55.44, a withdrawal of 20.00, and then show the balance. #include #include "ouracct.h" // for class bankAccount #include "ourstr.h" // for class string int main() { *** bankAccount Kay("Missie", "9876", 100.00); Kay.deposit(55.44); Kay.withdraw(20.00); cout << Kay.balance() << endl; return 0; } 7. (12pts) Given this function prototype with postconditions, determine the following information double diff(double a, double b); // POST: Returns the positive difference between a and b a. return type: *** double b. function name: *** diff c. number of arguments: *** 2 d. data type of arguments: *** double e. Write a valid call to diff with constant arguments: *** diff(3.2, 8.5); f. What is the return value of your function call? *** 5.3 8. (6pts) Circle the letters representing valid function prototypes assuming no #include directives. a. int large(int a; int b;); d. int f(int b); b. double c(double a, double b); e. void show(float x); c. large_int(a, b); f. character c(int a); *** b, d, and e are valid 9. (5pts) Write the output from the following program: #include double monthlyFee(int checks, int atms) { return(checks * 0.25 + atms * 0.10); } int main() { cout << "fee: " << monthlyFee(20, 10) << endl; return 0; } *** fee: 6 10a. (2pts) Write the name of the class given below. *** doLittle 10b. (4pts) Write the names of the member functions. *** doLittle huh 10c. (4pts) Write the names of the data members. *** a b 10d. (4pts) Write the output generated by this program. *** 85 80 #include class doLittle { public: doLittle(int initA, int initB); int huh(); private: int a, b; }; doLittle::doLittle(int initA, int initB) { a = initA; b = initB; } int doLittle::huh() { return ((a + b)/2); } int main() { doLittle one(80, 90), two(75, 85); cout << one.huh() << " " << two.huh() << endl; return 0; } 11. (9pts) Write the output generaterd by the following program #include #include "ourstr.h" string huh(int n) { if(n < 10) return "low"; else if(n < 20) return "mid"; else return "high"; } int main() { cout << huh(15) << endl; cout << huh(8) << endl; cout << huh(45) << endl; return 0; } *** mid low high 12. (11pts) Write a complete function that returns the larger of any three numeric values that have been received as value parameters. The following function call must be valid and also return 87: larger(75, 87, 63); *** double larger(double A, double B, double C) { if((A>=B) && (A>=C)) return A; if(B>=C) return B; // must be B or C at this point return C; } CSCI-15A Jim Murphy Page 4