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

Pir Mehr Ali Shah Arid Agriculture University Rawalpindi

Department of software engineering

Assignment no:2

Name: Abdul Sami Abbasi

Arid no: 23-ARID-879

Section: Evening 1-B

Department: software engineering


Q 1: Use a nested while loop to reproduce the following output
1
22
333
4444
55555

Output:

Q 2: Write a Program in C++ to find the remainder of two input Numbers without using %
Operator in C++
.
Output:

Q:3
Write a Program in C++ to get the loop start and loop end condition and then find the sum of
all nos between loop start and loop end value entered by user.
Output:

Q 4: The following table shows the approximate speed of sound in air, water, and steel.

Medium Speed

Air 1,100 feet per second

Water 4,900 feet per second

Steel 16,400 feet per second


Write a program that displays a menu allowing the user to select air, water, or steel. After

the user has made a selection, he or she should be asked to enter the distance a sound

wave will travel in the selected medium. The program will then display the amount of time it

will take. (Round the answer to four decimal places.)

Input Validation: Check that the user has selected one of the available choices from the

menu. Do not accept distances less than 0.

Output:

Q 5: An Internet service provider has three different subscription packages for its customers:
Package A: For $9.95 per month 10 hours of access are provided. Additional hours are

$2.00 per hour.

Package B: For $14.95 per month 20 hours of access are provided. Additional hours are

$1.00 per hour.

Package C; For $19.95 per month unlimited access is provided.

Write a program that calculates a customer's monthly bill. It should ask which package the

customer has purchased and how many hours were used. It should then display the total

amount due.

Input Validation: Be sure the user only selects package A, B, or C. Also, the number of

hours used in a month cannot exceed 744.

Output:
Q 7: The distance a vehicle travels can be calculated as follows:
distance = speed * time
For example, if a train travels 40 miles per hour for 3 hours, the distance traveled is 120
miles.
Write a program that asks the user for the speed of a vehicle (in miles per hour) and how
many hours it has traveled. The program should then use a loop to display the distance the
vehicle has traveled for each hour of that time period. Here is an example of the output:
What is the speed of the vehicle in mph? 40 How many hours has it traveled? 3
Hour Distance Traveled
1 40
2 80
3 120
Input Validation: Do not accept a negative number for speed and do not accept any value
less than 1 for time traveled.
Output:

Q 8: "Write a program that calculates the occupancy rate for a hotel. The
program should start by
asking the user how many floors the hotel has. A loop should then iterate
once for each
floor. In each iteration, the loop should ask the user for the number of rooms
on the floor
and how many of them are occupied.
After all the iterations, the program should display how many rooms the hotel
has, how
many of them are occupied, how many are unoccupied, and the percentage of
rooms that
are occupied. The percentage may be calculated by dividing the number of
rooms occupied
by the number of rooms.

Output:
Q 10: Write a program that displays a weekly payroll report. A loop in the
program should ask the
user for the employee number, gross pay, state tax, federal tax, and FICA
withholdings. The
loop will terminate when 0 is entered for the employee number. After the data
is entered, the
program should display totals for gross pay, state tax, federal tax, FICA
withholdings, and
net pay.
Input Validation: Do not accept negative numbers for any of the items
entered. Do not
accept values for state, federal, or FICA withholdings that are greater than the
gross pay. If
the sum state tax + federal tax
FICA withholdings for any employee is greater than gross pay, print an error
message and
ask the user to re-enter the data for that employee.
Q 9: Write a program with a loop that lets the user enter a series of integers. The user should
enter -99 to signal the end of the series. After all the numbers have been entered, the
program should display the largest and smallest numbers entered.
Output:
Output:

Q 11:
Write a program that uses a loop to display Pattern A below, followed by
another loop that
displays Pattern B.
Pattern A
*
**
***
****
*****
******
*******
********
*********
**********

Pattern B
**********
*********
********
*******
******
*****
****
***
**
*
Output:
Output:

THE END

You might also like