0% found this document useful (0 votes)
62 views3 pages

C++ Practice

This document outlines a lab exercise for an object-oriented programming course. It provides 7 programming questions for students to practice using basic C++ types, input/output, arithmetic operators, and conversions between measurement units. The questions involve tasks like calculating the sum and average of two numbers, converting between inches and feet, converting between seconds and hours/minutes/seconds, breaking down an amount of rupees into denominations, converting between Celsius and Fahrenheit temperatures, reversing a two-digit number, and converting a two-digit number from characters to an integer value.

Uploaded by

ayaan khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views3 pages

C++ Practice

This document outlines a lab exercise for an object-oriented programming course. It provides 7 programming questions for students to practice using basic C++ types, input/output, arithmetic operators, and conversions between measurement units. The questions involve tasks like calculating the sum and average of two numbers, converting between inches and feet, converting between seconds and hours/minutes/seconds, breaking down an amount of rupees into denominations, converting between Celsius and Fahrenheit temperatures, reversing a two-digit number, and converting a two-digit number from characters to an integer value.

Uploaded by

ayaan khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

Object-Oriented Programming (Lab Exercise)

Fall 2018
Software Engineering Department, NED University of Engineering and Technology

Week #2

Objective: For students to get some practice of:


 Using basic C++ types and user-defined objects
 Integer Types
 Basic Integer Operators

 C++ Input and Output


 Formatting Output
 Reading from the keyboard

 Named constants
 Expressions

Programming Exercise:
Use setw(width) manipulator for formatting output where required.

Q #1: Write a program that read two integers from the keyboard and print their sum and
average.

Sample run:
Enter first number: 25
Enter second number: 25
Sum is 50
Average is 25

Q #2: Write a program that prompts for a person’s height in inches. Convert this height
measurement into feet by using the conversion factor of f oot2Inch= 12 inch.
Now, the value obtained can easily, be translated into feet and inches which are
then output by the program.

Sample run:
Enter the height in inches: 20”
This is equivalent to 1’ 8”

Q #3: Write a program that prompts for time in seconds and output that time in hours,
minutes, and seconds. Here student will learn the usage of divide and modulus
arithmetic operators in integers.

Sample run:
Enter the time in seconds:3713
Hours in time is: 1
Minutes in time: 1
Seconds in time is: 53
Object-Oriented Programming (Lab Exercise)

Fall 2018
Software Engineering Department, NED University of Engineering and Technology

Q #4: Write a program that prompts for amount in rupees and show how many 1000’s,
500’s, 100’s, 50’s, 10’s, 5’s, 2’s and 1’s in it.

Sample run:
Enter amount in rupees: 5788
1000’s in the given amount is: 5
500’s in the given amount is: 1
100’s in the given amount is: 2
50’s in the given amount is: 1
10’s in the given amount is: 3
5’s in the given amount is: 1
2’s in the given amount is: 2
1’s in the given amount is: 1

Q #5: Write a program that calculates the temperature in Fahrenheit. For that it prompts
for temperature in Celsius degrees. Formula to calculate Fahrenheit temperature
is Fahrenheit=Celsius (9/5+32). Once if the task done do the vice versa i.e.
Celsius=5/9(Fahrenheit -32)

Sample run:
Enter the Fahrenheit temperature: 98.6
Celsius Temperature: 37.0

Q #6: Write a program that inputs a two digit integer value, and output its reverse order.
Sample run:
Enter a 2 digit integer value: 45
Reverse of this value is: 54

Q #7: Write a program that reads the two digit nmber as two characters chTen and
chUnit and convert that two digit number into an integer value. In order to
compute the corresponding integer value, each character must be converted to
the digit in the range 0 to 9. this is done by subtracting 48(‘0’) from the ASCII
value of the character.
ValueTen=chTen-‘0’; // ’8’-‘0’ is 8
ValueUnit=chUnit-‘0’; // ’2’-‘0’ is 2

To create integer value fro m, the positional value of each digit must be used. In this
case multiply ValueTen by 10.

M=ValueTen*10+ValueUnit;//m=8*10+2=82

Sample run:
Enter a two digit number: 82
Numeric Value is: 82

-------------------------------------------------------------------------------------------------------------------
Object-Oriented Programming (Lab Exercise)

Fall 2018
Software Engineering Department, NED University of Engineering and Technology

Student Evaluation of Exercise:

Remarks (By the Teacher):

You might also like