Sei sulla pagina 1di 4

COMSATS Institute of Information Technology, Sahiwal

DEPARTMENT OF COMPUTER SCIENCE


Assignment # 03
(Submission Deadline: [In soft form] 5/11/2015, 11:59 PM [in hard form] 6/11/2015, 10 AM)
Total Marks: 50
Instructor:

Arshad Farhad

Course:

ICP

Note: Each question carries equal marks!


Copied assignments will get zero for sure!

1. Write a program to play a numbers guessing game. The user thinks of a number between 1
and 100 and your program asks questions to figure out what the number is (e.g., "Is the
number you are thinking of less than 50?"). Your program should be able to identify the
number after asking no more than seven questions. Hint: Use the < and <= operators and the
if-else construct. Moreover, print your name, reg.no and class after success!
[5]
2. Write a program that performs the following calculation.
- add, subtract, multiply, divide, and modulus (remainder) - on two input values.
The use input 3 arguments: two double/int values and a character to represent an operation. If the
entry arguments are 95, 3, and '%', the program output should be The Mod of 95 and 3 is 2."
Furthermore, whenever an operation is being performed it should print your name, reg.no and class
5 times as shown in figure below. Hint: use while loop.
[5]

3. Sometimes people are concerned about to track their automobiles mileage. One driver has kept
track of several tankfuls of gasoline by recording miles driven and gallons used for each tankful.
Create a C++ program that uses a while structure to input the miles driven and gallons used for
each tankful. The program should calculate and display the miles per gallon obtained for each
tankful. After processing all input information, the program should calculate and print the

combined miles per gallon obtained for all tankfuls. Likewise, print your name, reg.no and class
at the end as shown in figure.
[10]

4. Develop a C++ program that will determine whether a department store customer has exceeded
the credit limit on a charge account. For each customer, the following facts are available:
a) Account number (an integer)
b) Balance at the beginning of the month
c) Total of all items charged by this customer this month
d) Total of all credits applied to this customer's account this month
e) Allowed credit limit
The program should use a while structure to input each of these facts, calculate the new balance
(= beginning balance + charges - credits) and determine whether the new balance exceeds the
customer's credit limit. For those customers whose credit limit is exceeded, the program should
display the customer's account number, credit limit, new balance and the message "Credit
limit exceeded." Additionally, if user enter an invalid account number (-1), it should print Invalid
account number similarly, it should print your name, reg.no and class 5 times by using while loop
as shown in figure below.
[10]

5. In a company a salesperson receives $200 per week plus 9% of their gross sales for that week.
For example, a salesman who sells $5000 worth of something in a week, he receives $200 plus 9%
of $5000, or a total of $650. Write a program to input each salesmans gross sales for last week to
calculate his earnings. Process one salespersons figures at one time.
[10]

6. Write a program that find the largest among 10 numbers by using a while structure. Your
program should use three variables, as follows:
counter: A counter to count to 10 (i.e., to keep track of how many numbers have been input
and to determine when all 10 numbers have been processed).
number: The current number input to the program.
largest: The largest number found so far.

[10]

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.

-Good Luck-

Potrebbero piacerti anche