COSC 1415 Practice Test #3
1. Declare an array to store 20 numbers that contain a decimal point. select Array[20]; int A(20); Array float(20); float B[20];
2. Declare an array to store the months of the year as text (e.g. January). select months[20]; string Months[20]; string Months(12); none of the above
3. Declare an array to store five integers and initialize it with the numbers 1,2,3,8,4 select int N[6] = (1,2,3,8,4); int N[5] = {1,2,3,8,4}; int N[5] == (1,2,3,8,4); none of the above
What will the following statements output? Note: if any of the string operations change the value of a variable, assume all subsequent questions use the new values.
string A = "question"; string B = "I have a ";
4. cout << B + A[1]; select question I have a I have a q I have a u - none of the above -
5. cout << B + A.substr(0,3); select I have a que I have a question I have a q no output
6. cout << B.size() - A.size(); select 1 17 2 16
7. cout << B.insert(2,"don't") + A; select don't I have a question I don't have a question I don'thave a question no output
8. string B = "I have a "; cout << B.find("a",4); select 1 3 4 7
9. string Car = "Ferrari"; Car.insert(0,"Yellow"); select Ferrari Yellow Yellow Ferrari - no output -
10. cout << Car.substr(0,4) + " " + Car.substr(3,2)+"ud"; select Yellow Ferrari Yel lloud Yell loud Yellow Ferr
11. What library do you have to include to read data from a file? select iostream.h string fstream.h stdlib.h
12. What will the preceding code output to the screen?
select 10 8 6 4 10 8 6 4 2 10 8 6 4 2 0 - Nothing -
What would be the function header line for each of the following?
13. A function to calculate the area of a square. select float AreaSquare(float Side) string AreaSquare(float Side1, Side2) int AreaSquare(float Base, float Height) int AreaSquare(float Pi, float Side)
14. A function to calculate the volume of a sphere. select string VolSphere(float Radius) float VolSphere(float Radius, float Pi) float VolSphere(float Radius) none of the above
15. A function to convert gallons to liters. select float GallonsLiters(float Gallons) float GallonsLiters(float Liters) void GallonsLiters(float G, float L)) none of the above
16. A function to display all the vowels contained in a word. select int Vowels(char V) string Vowels(string Word) char Vowels(string Word) none of the above
17. A function that returns true if a number is even or false if the number is odd. select string EvenNumber(int Number) int EvenOdd(float Number) int EvenOdd(char A) bool EvenNumber(int Number)
You got out of correct. Your Score: %