Practice1 1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

1.

Adding Fractions using Structures: Write a C++ program to add two


fractions and display the result fraction. Your program will prompt the user
to input fraction 1 and fraction 2. The numerator and denominator of each
fraction are input separately by space. See the example output below. You
will need to use a C++ structure to define a fraction. The structure has two
members: numerator and denominator.
Enter fraction 1(numerator and denominator): 1 2
Enter fraction 2(numerator and denominator): 2 5
Result: 9/10
2. Four Fraction Calculator as Structure: Revise the four-function fraction
calculator program of Assignment_08Nov2017.pdf (Exercise#7), so that
each fraction is stored internally as a variable of type struct fraction as asked
in Exercise#1 of this assignment.
3. Storing Phone Number as a Structure: A phone number, such as (212)
767-8900, can be thought of as having three parts: the area code (212), the
exchange (767), and the number (8900). Write a program that uses a
structure to store these three parts of a phone number separately. Call the
structure phone. Create two structure variables of type phone. Initialize one,
and have the user input a number for the other one. Then display both
numbers. The interchange might look like this:
Enter your area code, exchange, and number: 415 555 1212
My number is (212) 767-8900
Your number is (415) 555-1212
4. Operator Overloading: Augment the time structure referred to in Exercise
given in your lab-practice (3Jan2018) to include overloaded increment (++)
and decrement (--) operators that operate in both prefix and postfix notation
and return values. Add statements to main() to test these operators.
5. Employee’s Record: Create a structure called employee that contains two
members: an employee number (type int) and the employee’s compensation
(in dollars; type float). Ask the user to fill in this data for three employees,
store it in three variables of type struct employee, and then display the
information for each employee.
6. Month-Day-Year: Create a structure of type date that contains three
members: the month, the day of the month, and the year, all of type int. (Or
use day-month-year order if you prefer.) Have the user enter a date in the
format 12/31/2001, store it in a variable of type struct date, then retrieve the
values from the variable and print them out in the same format.
7. Volume of a Room: Create a structure called Volume that uses three
variables of type Distance (given below) to model the volume of a room.
Initialize a variable of type Volume to specific dimensions, then calculate
the volume it represents, and print out the result. To calculate the volume,
convert each dimension from a Distance variable to a variable of type float
representing feet and fractions of a foot, and then multiply the resulting three
numbers.

8. Currency Conversion: Create a structure called sterling that stores money


amounts in the old-style British system discussed in Exercise 8 in
“Assignment_25Oct2017”. The members could be called pounds, shillings,
and pence, all of type int. The program should ask the user to enter a money
amount in new-style decimal pounds (type double), convert it to the old-
style system, store it in a variable of type struct sterling, and then display
this amount in pounds-shillings-pence format.
9. Circle: Create a structure CircleStructure that stores centeral coordinates
and radius of the circle. Take input for radius and centeral coordinates from
user. Pass this structure to a function area_circum( ) that will compute and
display the area and circumference of the circle.
10. Student Record: Create a structure named student_record. Declare
following members of this structure
Name, Age, Discipline, Semester, Grade, %age
Save the record of 10 students in structure format. Take input from the user
and display all the information using a separate display_record ( ) function.
11. Movies Record: Create a structure that will keep record of movies. Your
structure may have the elements like movie name, year released, director,
budget, rating. Display the record entered in the main( ).
12. Books Record: Create a structure to keep record of books in a library.
Select the structure elements wisely.
--------------------------

You might also like