Csdp 221 Quiz #3 Spring 2012
Total Page:16
File Type:pdf, Size:1020Kb
CSDP 221 QUIZ #3 SPRING 2012
1. Write a statement(s) for computing the remainder of the division of int num1 with int num2 and storing the result in int answer. (2)
2. What is the result of the following typecasting statements? (2)
A) int(7.4)
B) float(6)
C) float(10/6)
D) float(10)/float(6)
3. A function prototype is a declaration of a function that omits the function body but does specify the function's return type, name, and argument types. Write function prototypes for the following: (5)
A) A void function (never returns a value to the caller) named Print with one float argument.
B) A void function named Hello with one float argument and one string argument.
C) A float returning function named taxCalculator with two float arguments.
D) An integer returning function named Bonus with no arguments.
E) A void function named ForFun with no arguments. 4. Write a statement for printing the value in string variable name in 10 character positions. (1)
5. Suppose the input data are entered as follows: (2) 10 20 50 60 70 80 The input statements that read it are cin >> a >> b >> c; cin >> d; What are the contents of the variables a, b, c, and d after the statements have executed?
PLEASE TURN OVER 6. Suppose the input data are entered as follows: (1) 10 20 30 40 50 60 70 80 The input statements that read it are cin >> a >> b >> c; cin >> d >> e >> f; cin >> a >> b; What are the contents of the variables a and b after the statements have executed?
7. Write C++ statements for (3)
A) Declaring two string variables FName and LName.
B) Prompting the user to enter his/her first name and last name.
C) Getting the first name and last name using cin into FName and LName.
8. Write C++ statements for getting values into three character variables named c1, c2, and c3 using the get function. (3) 9. Write a C++ statement for ignoring (or skipping) 10 characters or until ‘#’ from the standard input stream (keyboard). (2)
10. Write C++ statements for getting values into string variables city and state using the getline function. (2)
11. Write C++ statements for (2)
A) Declaring an input file stream variable (name is your choice).
B) Opening a file named “input.txt” using the above variable.
Maximum Points: 25