TEST 1 CS 1410 Intro. To Computer Science Name KEY October 13, 2010 Fall 2010 Part I: Circle one answer only. (2 points each) 1. The decimal representation of binary number 11011 2 is a) 19 10 b) 29 10 c) 27 10 d) 37 10 e) 47 10 2. The binary representation of decimal number 41 10 is a) 41 10 b) 110011 2 c) 101001 2 d) 100101 2 f) 101011 2 3. The binary number 1010111110 2 can be represented in Hex (base 16) as a) 2AE 16 b) 2BE 16 c) AF2 16 d) AF4 16 e) AF8 16 4. To store a character in C++, it requires a memory space of a) 4 bits b) 8 bits c) 16 bits d) 32 bits 5. In UNICODE, it requires 2 bytes or 16 bits to represent a character in different languages including English language. Which of the following code represents English character? a) 00000001 00000111 b) 00000010 01110101 c) 00000100 01011111 d) 00000011 01110111 e) 00000000 01010111 6. If each pixel of a picture can have one of the 32 colors,, how many bits it requires to store color information? a) 2 bits b) 3 bits c) 4 bits d) 5 bits e) 6 bits 7. One pixel of a picture requires 8 bits to store color information. At least, how many bytes necessary to store picture with 80,000 pixels? a) 300,000 b) 240,000 c) 100,000 d) 80,000 8. How many bits does it requires to store an RGB-color picture? a) 8 b) 16 c) 24 d) 32 9. Which of the following is a high-level language? a) Machine code b) Java language c) Assembly language d) Mnemonic code 10. Which header file is needed if your program uses setprecision? a) iostream b) iomanip c) fstream d) cmath 11. Which of the following is a valid identifier in C++? a) LastFirstMiddle b) Last.First.Middle c) Last-First-Middle d) Last&First&Middle 12. In C++, cin refers to: a) a CD-ROM drive b) a floppy disk drive c) the display screen d) the keyboard
Test 1: page 2 of 6 13. In C++, if we want a variable to hold or store a decimal value, an appropriate type for declaring the variable is a) string b) double c) char d) int 14. After the following statement is executed, what does the computer do? int interestrate; a) Declare interestrate to be variable b) Set interestrate to be int type c) Allocate a memory space to interestrate d) Declare interestrate to be int type 15. What is the output of the following code? int Integer1 = 57; cout<<"integer1"; a) 57 b) "Integer1" c) Integer1 d) syntax error 16. Which of the following is a valid constant declaration? a) const int LastYear = 2001; b) const int = 2001; c) const 2001; d) const int 2001 = Lastyear; 17. What is the value of the following C++ expression: 20/3? a) 6.67 b) 6 c) 2 d) 0 18. What is the value of the following C++ expression: 20/3.0? a) 6.67 b) 6 c) 2 d) 0 19. What is the value of the following C++ expression: 20.0/3? a) 6.67 b) 6 c) 2 d) 0 20. In C++, the value of the expression 27%4 is a) 1 b) 2 c) 3 d) 4 21. In C++, the value of the expression 13/3%2 is a) 1 b) 2 c) 3 d) 4 22. What is the value of the expression: 2 + 3 * 4-5 a) -5 b) 20 c) -1 d) 9 23. Which of the following statements prints Have A Nice Day! on one output line? a) cout<<"have A "<<endl; cout<<"nice Day!"<<endl; b) cout<<"have A "; cout<<"\nnice Day!"<<endl; c) cout<<"have A " <<"Nice Day!"<<endl; d) cout<<"have A " <<"\nnice Day!"<<endl; 24. What manipulator(s) will set the floatingpoint values to decimal number? a) fixed b) setw c) left d) right
Test 1: page 3 of 6 25. If we want a program to use file for input or output, we have to include header file a) iostream b) iomanip c) cmath d) fstream 26. Assume that the declaration of logical file variable is fstream InFile; Which of the following code is used to open the file to read? a) InFile.open("Test.txt",ios::out); b) InFile.open("Test.txt",ios::in); c) InFile.open("Test.txt"); d) All of the above 27. If Age is an int variable containing the value 45, which output statement will produce the following output: 1234567890 Age: 45 a) cout<<"1234567890"<<endl <<"Age:"<<setw(2)<<Age; b) cout<<"1234567890"<<endl <<"Age:"<<setw(3)<<Age; c) cout<<"1234567890"<<endl <<"Age:"<<setw(4)<<Age; d) cout<<"1234567890"<<endl <<"Age:"<<setw(5)<<Age; 28. What is the output of the following program fragment? int INumber1 = 3214, INumber2 = 83; cout<<setw(5)<<inumber1<<endl <<setw(5)<<inumber2<<endl; a) 3214 83 b) 3214 83 c) 32140 83000 d) 3214 83 29. What is the output of the following program fragment? double DNumber1 = 32.145; double DNumber2 = 283.75; cout<<fixed<<setw(2)<<dnumber1<<endl <<DNumber2<<endl; a) 32.145 283.75 b) 32.145000 283.750000 c) 32.145 283.75 d) 32.1450 283.750 30. Given the following code: char Letter1,Letter2,Letter3; cin>>letter1>>letter2>>letter3; cout<<letter1<<letter2<<letter3; and the input as follows 12 34 What is the output? a) 123 b) 12 c) 12 3 d) 12 34 31. Given the following code: char Letter1,Letter2; int Num; cin>>letter1>>letter2>>num; cout<<letter1<<letter2<<num; and the input as follows 123456 What is the output? a) 123 b) 1234 c) 12345 d) 123456
Test 1: page 4 of 6 32. Given the input stream as 123 4567 89ABCDEF GH\n 987 65\n What is the output of the following code? cin>>inum1>>inum2; cin.ignore(50,'d'); cin>>inum3; cout<<inum1<<' '<<INum2<<' ' <<INum3; a) 123 4567 89 b) 123 4567 987 c) 123 4567 EF d) 123 4567 65 33. Given the input stream as 1234567890 ABCDEF \n GH 987 65\n What is the output of the following code? cin.ignore(10,\n); cin>>letter1>>letter2; cin.ignore(100,'d'); cin>>letter3, cout<<letter1<<' '<<Letter2 <<' '<<Letter3; a) A B b) A B C c) A EF d) A E 35. The following is a formula to compute the final price after 25% discount: price = price (1- discount) Assume the following declaration: const double Rate = 0.25; double Purchase; Which of the following assignment statement that computes the final price? a) Price = Price*(1-Discount); b) Purchase = Purchase*(1-Rate); c) Purchase = Purchase(1-Rate); d) Price = Price(1-Discount); 34. Which assignment statement could be used to store the letter A into the char variable somechar? a) somechar = "A"; b) somechar = A; c) somechar = 'A'; d) somechar == "A"
Test 1: page 5 of 6 Part II (30 Points) An online retail company will charge 8.25% sales tax if an order will be delivered anywhere in Texas. A standard of $5.95 shipping will be added to all order. Write a C++ program to determine the total sales amount of an order that the company receives. The total sales amount is the sum of the amount of the order, sales tax if applicable, and the shipping cost. The program will ask for the amount of the order and the state for delivery. Then output the amount of the order, sales tax, the shipping cost and the total sales amount. All numbers should be displayed in with 2 decimal places. Use setw() to format the output. The following are samples of input and output. Email project folder to ongards4@yahoo.com Input/output samples:
Test 1: page 6 of 6 #include <iostream> #include <iomanip> #include <string> using namespace std; int main() { const double Shipping = 5.95; const double taxrate =.0825; double Sales, TotalAmount, Tax; string State; cout<<"enter the amount of the order -->"; cin>>sales; cout<<"enter the state where the order will be delivered. TX for Texas, AZ for Arizona -->"; cin>>state; if (State == "TX") Tax = Sales*taxRate; else Tax = 0; TotalAmount = Sales + Shipping + Tax; cout<<fixed<<setprecision(2); cout<<endl; cout<<"**************************************************"<<endl; cout<<"** Online Retail Company **"<<endl; cout<<"**************************************************"<<endl; cout<<"\nthe order amount is "<<setw(15)<<"$"<<setw(9)<<sales; cout<<"\nthe sales tax is "<<setw(18)<<"$"<<setw(9)<<tax; cout<<"\nthe shipping is "<<setw(19)<<"$"<<setw(9)<<shipping; cout<<"\nthe total amount of the order is "<<setw(2)<<"$"<<setw(9)<<totalamount; cout<<"\n\nthank you for shopping with us!!!"; cin.get(); cin.get(); } return 0;