Anda di halaman 1dari 5

National University of Computer and Emerging Sciences

Laboratory Exercise
for
Introduction to Computing Lab

(CL 116)
Lab Instructor: Shahi Dost
FAST – NU, Fsd Campus

ITC Lab 6 Manual


Objectives:

 Logical Operators, Relational operators.


 Conditional structures:
 if, if-else, if-else-if, nested if
 Practice C++ programming problems.

Note: Carefully read the following instructions.

1. Write a C++ statement(s) for each of the following task one after the other, in the same order.
2. Make a Microsoft Word file and past all of your C++ code in MS word files one by one.
3. Take at least one snapshot of every task and insert after every task in MS word file.
4. First think about statement problems and then write/draw your logic on copy.
5. After copy pencil work, code the problem statement on MS Studio C++ compiler.
6. At the end, when you done your today lab tasks, attached MS word file and make your
submission on slate.
Problem 6.1: Conditional statements

Use logical operator to implement the following expressions:

At the end comments in your c++ program the operator precedence of above expression?

Hint: cout<<(expression);
//+,- etc.

ITC Lab
Page 2
FAST – NU, Fsd Campus

Problem 6.2: Perform the following tasks.

Suppose you have the following declarations:


bool found = true;
int age = 20;
double hours = 45.30;
double overTime = 15.00;
int count = 20;
char ch = 'B';

Execute the following expression:

Problem 6.3: Write C++ programs for the following tasks.

1. Write a program that prompts the user to input a number. The program should then
output the number and a message saying whether the number is even, odd, or zero.

2. Write a program that prompts the user to input three numbers. The program should
then output the numbers in descending order.

ITC Lab
Page 3
FAST – NU, Fsd Campus

Problem 6.4: Use both if-else & Switch statements for the problem statements.

1. The roots of the quadratic equation ax2 + bx + c = 0, a!= 0 are given by the following
formula:

In this formula, the term b2-4ac is called the discriminant. If b2-4ac = 0, then the
equation has a single (repeated) root.
If b2-4ac > 0, the equation has two real roots.
If b2-4ac<0, the equation has two complex roots.

Write a C++ program that prompts the user to input the value of a (the coefficient of
x2), b (the coefficient of x), and c (the constant term) and outputs the type of roots
of the equation.
2. Write a new C++ program and use switch statements to solve the above problem.

Problem 6.5: Calculate total price of tile using if-else statements.

Write a program that mimics a calculator. The program should take as input two integers and
the operation to be performed. It should then output the numbers, the operator, and the
result. (For division, if the denominator is zero, output an appropriate message.) Some sample
outputs follow:
3+4=7
13 * 5 = 65

Problem 6.6: Calculate price of railing material.

A bank in your town updates its customers’ accounts at the end of each month. The bank offers
two types of accounts: savings and checking. Every customer must maintain a minimum
balance. If a customer’s balance falls below the minimum balance, there is a service charge of
$10.00 for savings accounts and $25.00 for checking accounts. If the balance at the end of the
month is at least the minimum balance, the account receives interest as follows:

ITC Lab
Page 4
FAST – NU, Fsd Campus

a. Savings accounts receive 4% interest.


b. Checking accounts with balances of up to $5,000 more than the minimum balance
receive 3% interest; otherwise, the interest is 5%.

Write a program that reads a customer’s account number (int type), account type (char; s
for savings, c for checking), minimum balance that the account should maintain, and current
balance. The program should then output the account number, account type, current balance,
and an appropriate message. Test your program by running it two times, using the following
data:
46728 S 1000 2700
87324 C 1500 7689

You are done with your exercise(s), make your submission on slate.
Submission by email or USB will get (-50) % of total lab marks 

ITC Lab
Page 5

Anda mungkin juga menyukai