Sunteți pe pagina 1din 3

COMSATS Institute of Information Technology, Sahiwal

DEPARTMENT OF COMPUTER SCIENCE


Assignment # 02
(Deadline: 30/10/2015, 10:00 AM)
Instructor:

Arshad Farhad

Total Marks: 30
Course:

ICP

Note: Q1-10 caries 1 Mark each. Q11-20 caries 2 marks each. Also, guidelines are given at
the end of this document.
In case, copied assignments found both the assignments will get zero!

1. If you want the user to input an integer value into your program for a variable named number,
what are two lines of code you could write to ask the user to do it and to input the value into your
program?
2. What is \n called and what purpose does it serve?
3. How would you write?
cout << "Hello, ";
cout << first_ name;
cout << "!\n";
as a single line of code?
4. What is a literal?
5. What kinds of literals are there?
6. What effect do tabs, spaces, and new lines have on the program?
7. What are typical sizes for a char, an int, and a double?
8. What measures do we use for the size of small entities in memory, such as ints and strings?
9. What is the difference between = and ==?
10. What is an initialization and how does it differ from an assignment?
11. Write a program that doesn't do anything, but declares a number of variables with legal
and illegal names (such as int double = 0; ), so that you can see how the compiler reacts.

12. Write a program in C++ that converts from miles to kilometers. Your program should have a
reasonable prompt for the user to enter a number of miles. Hint: There are 1.609 kilometers to the
mile
13. Write a program that prompts the user to enter two integer values. Store these values in int
variables named val1 and val2. Write your program to determine the smallest, largest, sum,
difference, product, and ratio of these values and report them to the user.
14. Modify the program above (Q13) to ask the user to enter floating-point values and store
them in double variables. Compare the outputs of the two programs for some inputs of your
choice. Are the results the same? Should they be? What's the difference?
15. Write a program to test an integer value to determine if it is odd or even. As always, make sure
your output is clear and complete. In other words, don't just output yes or no." Your output
should stand alone, like "The value 4 is an even number ."
16 Write a program that generates the following output:
10
20
19
Use an integer constant for the 10, an arithmetic assignment operator to generate the 20, and a
decrement operator to generate the 19
17. Write a program that generates the following table:
Year Result
----------------1990

135

1991

7290

1992

11300

1993

16200

Use a single cout statement for all output.


Also, revise the program to show the same table by using cin object. Which takes all the values
from user and draw the same table.

Guidelines:

Every student must print his/her information in each program: (Name, Reg.no, and Class)

The assignment should contains original outputs (in picture form). Hint: use snipping tool to capture output image.
However, while capturing picture using snipping tool, capture the time & date. A sample picture is shown as below. Try
to resize the picture, so that it can cover little space but the output must be clear and visible.

-Good Luck-

S-ar putea să vă placă și