Term Test

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

TECHNOLOGICAL UNIVERSITY OF THE PHILIPPINES TAGUIG CAMPUS

Km. 14 East Service Road, Western Bicutan, Taguig

COMP 312 Computer Programming Term Test Name:__________________________________ TEST I. True or False
_______________1. C++ is not case sensitive. For example, count and COUNT are two different identifiers. _______________2. Variables must be declared before they are used. Other than following this rule, a variable declaration may appear anyplace. _______________3. Boolean expressions are evaluated similar to the way arithmetic expressions are evaluated. _______________4. A switch statement is a good way to implement a menu for the user of your program. _______________5. The C++ loop statements are the if-else and for statements. _______________6. A for loop can be used to obtain the equivalent of the instruction repeat the loop body n times. _______________7. The C++ branching statements are the while and do while statement. _______________8. Comments are use to explain major subsection or any unclear part of the program _______________9. A C++ identifier must start with either a letter or the underscore symbol and #, and the remaining characters must all be letters, digits, or the underscore symbol. _______________10. C++ identifiers are case sensitive and have a limit to their length. _______________11. Variable names and other names in a program should at least hint at the meaning or use of the thing they are naming. _______________12. To start a new output line, you can include \n in a quoted string _______________13. It is not a good idea to output a newline instruction at the end of every program. _______________14. Some compilers will not output the last line of your program unless you include a newline instruction at the end _______________15. It is possible to keep output and input on the same line, and sometimes it can produce a nicer interface for the user. _______________16. You can assign a value of an integer type, like int, to a variable of a floating-point type, like double, and not vice versa. _______________17. Use enough parentheses in arithmetic expressions to make the order of operations clear. _______________18. The object cout is used for console output. _______________19. A \n in a quoted string or an endl sent to console output starts a new line of output. _______________20. The object cin is used for console output _______________21. In order to use cin, cout,, you should place the following directives near the beginning of the file with your program: #include <iostream> _______________22. A computers main memory is divided into a series of numbered locations called bits. _______________23. A sequence of precise instruction is called algorithm _______________24. The variable name is used to reference the stored value throughout the program _______________25. C++ offers several ways for decisions to be made, the simplest of which is the if statement TEST II. Problem Solving 1. It is difficult to make a budget that spans several years, because prices are not stable. If your company needs 200 pencils per year, you cannot simply use this years price as the cost of pencils two years from now. Because of inflation the cost is likely to be higher than it is today. Write a program to gauge the expected cost of an item in a specified number of years. The program asks for the cost of the item, the number of years from now that the item will be purchased, and the rate of inflation. The program then outputs the estimated cost of the item after the specified period. Have the user enter the inflation rate as a percentage, such as 5.6 (percent). Your program should then convert the percentage to a fraction, such as 0.056, and should use a loop to estimate the price adjusted for inflation. (Hint: Use a loop.) 2. A government research lab has concluded that an artificial sweetener commonly used in diet soda will cause death in laboratory mice. A friend of yours is desperate to lose weight but cannot give up soda. Your friend wants to know how much diet soda it is possible to drink without dying as a result. Write a program to supply the answer. The input to the program is the amount of artificial sweetener needed to kill a mouse, the weight of the mouse, and the weight of the dieter. To ensure the safety of your friend, be sure the program requests the weight at which the dieter will stop dieting, rather than the dieters current weight. Assume that diet soda contains one -tenth of 1% artificial sweetener. Use a variable declaration with the modifier const to give a name to this fraction. You may want to express the percentage as the double value 0.001. 3. Workers at a particular company have won a 7.6% pay increase retroactive for six months. Write a program that takes an emp loyees previous annual salary as input and outputs the amount of retroactive pay due the employee, the new annual salary, and the new monthly salary. Use a variable declaration with the modifier const to express the pay increase. 4. A metric ton is 35,273.92 ounces. Write a program that will read the weight of a package of breakfast cereal in ounces and output the weight in metric tons as well as the number of boxes needed to yield one metric ton of cereal.

Date:_______________

You might also like