0% found this document useful (0 votes)
28 views

Class

1. The document describes 8 programming exercises to create classes in C++. The first exercise asks to create a Calculator class with functions to add, subtract, multiply and divide two numbers. The second asks to create a Student class with name and ID attributes and corresponding set and get functions. The third asks to create a Rectangle class with length, width, and area attributes and corresponding functions. The remaining exercises ask to create various classes to calculate areas of shapes, define a Book class, create a Person class, define a Time class, and create an Employee class with ID, name, wage attributes and corresponding set and get functions.

Uploaded by

Doaa Idais
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Class

1. The document describes 8 programming exercises to create classes in C++. The first exercise asks to create a Calculator class with functions to add, subtract, multiply and divide two numbers. The second asks to create a Student class with name and ID attributes and corresponding set and get functions. The third asks to create a Rectangle class with length, width, and area attributes and corresponding functions. The remaining exercises ask to create various classes to calculate areas of shapes, define a Book class, create a Person class, define a Time class, and create an Employee class with ID, name, wage attributes and corresponding set and get functions.

Uploaded by

Doaa Idais
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Class.

1. Write C++ program to design a simple calculator using class and object in C++.
The Calculator class contains 4 public member functions
.get() that asks the user to enter two numbers
.add(): This function returns A + B
.sub(): This function returns A – B
.mul(): This function returns A * B
.div(): This function returns A / B
. It also checks if B is 0 or not.
Inside the main print the 4 choices for the user then let him/her choose the function.

2. Create class of student that have attributes of:


 Name(string)
 ID (int)
the class should also have set and get function.
Inside the main create an object from class student and give the object data using set function:
Name=Ali
ID=2019
then print the data on screen using get function.

3. Create a rectangle class which contain the following fields(attributes, data):


 Length (float)
 Width (float)
And these following functions:
setLength, setWidth, getLength, getWidth, getArea.
- Inside the main create an "box" object, then ask the user to enter the value of width and length
for the box.
- Print the value of Area.
NOTE Area=Length*width.
4. Create a class named calculate that contain area variable.
 You have to calculate the area of circle, rectangle, square and triangle using a function.
 Use the same function for rectangle and square.
 Area of circle =22/7 * radius2.
 Area of rectangle and square = length * width.
 Area of triangle =half *length*width.

5. Define a class BOOK with the following specifications :


Private members of the class BOOK are
BOOK NO integer type
BOOKTITLE 20 characters
PRICE float (price per copy)
TOTAL_COST() A function to calculate the total cost for N number of copies
where N is passed to the function as argument.
Public members of the class BOOK are
INPUT() function to read BOOK_NO. BOOKTITLE, PRICE
PURCHASE() function to ask the user to input the number of copies to be
purchased. It invokes TOTAL_COST() and prints the total cost to be paid by the user.
Note : You are also required to give detailed function definitions.

6. Create a class and name it Person, this class should include the following data members:
• First name (string)
• Last Name (string)
• Age (int)
• Height (double)
Your class should have the following:
• Set and get functions for all variables.
• Print function that can display the results.
• Inside the main function, call set function for object obj.
• Print the data by calling print function.

7. Create a time class  that


:contain these private members 
Hour (int)
Minute( int)
Second (int)

:The class will contain

● get function for all class members


● Parametrized constructor that takes three parameters (hour,minute,second)
● :Inside main function 
● Create an object then call parametrized constructor and get functions.

8. Write a complete C++ program that implements the following:


A. A class called Employee. The class Employee data methods should include:
o ID: (int).
o Name: (String).
o Wage: (array of 5 int).

The class Employee should include the following member functions:

o For each data member: ID, Name and Wage provide a parametrized Set function to
store the received parameters for each one of those data members.
o For each data member: ID, Name, and Wage provide an empty Get function to
return the valuefor each one of those data members.
o Provide ComputeAnnualRevenue function that calculate the summation for the
array Wage.
B. The main function should include:
o Definition for the object Obj from the class Employee.
o Calling statement for the Set functions, and the ComputeAnnualRevenue function of
the object obj.
o Promote to the user to enter arguments to be passed for the functions
o Printing statements for the object obj information by calling the Get functions.

You might also like