Starting from:

$35.99

OOP-BASIC-Object Oriented Programming: Assignment 3 Solved

Question 1: implement a  structure Employee. An employee has a name (a char *) and a salary (a double). Write a default constructor, a constructor with two parameters (name and salary), and methods char* getName()  double  getSalary()  to return the name and salary.  

Write a small global function TestEmployee() to test your structure.

Creating a new employee.

Please type the name:

Larry Bird

Please specify the salary: 200000 New employee has been created.

Name of employee: Larry Bird

Salary: 200000.0

Thank you for testing structure Employee.

Question 2: 

Implement a structure Car with the following properties. A car has a certain fuel efficiency (measured in miles per gallon or liters per km pick one) of type float and a certain amount of fuel in the gas tank of type float. The efficiency is specified in the constructor, and the initial fuel level is 0. Supply a method drive (float) that simulates driving the car for a certain distance, reducing the fuel level in the gas tank, and methods float get fuel level() returning the current fuel level, and void tank(float), to tank up. 

Sample usage of the structure:  

 void main() {

  Car myBeemer(29);  

  cout<<myBeemer.getFuelLevel()<<endl;    myBeemer.tank(20);  

  cout<<myBeemer.getFuelLevel()<<endl;    myBeemer.drive(100);  

  cout<< myBeemer.getFuelLevel()<<endl;  

}  

Should produce:  

 

0.0

20.0

16.551724137931036 

Question 3: 
 

Implement a structure Circle (think of its data members) that has methods  

•      float getArea() and  

•      float getCircumference()  

In the constructor, supply the radius of the circle.

 

Please specify the radius of your circle: 1.0 Circle created.  

Area: 3.141592653589793 Circumference: 6.283185307179586 Good-bye! 

Question 4:
 

Define a structure FlightInfo in C++ with following description: 

Private Members

A data member FlightNumber of type integer

A data member Destination of type char*

A data member Distance of type float

A data member Fuel of type float 

A member function void calFuel() to calculate the value of Fuel as per the following criteria and set its corresponding data member

            Distance                                                          Fuel

            <=1000                                                            500             more than 1000  and <=2000                         1100             more than 2000                                               2200  Public Members

A function void feedInfo() to allow user to enter values for Flight Number, Destination, Distance & call function void calFuel() to calculate the quantity of Fuel

A function void showInfo() to allow user to view the content of all the data members A function float getFuel() that returns the current fuel value. 

 

Question 5: 

Implement a structure Employee2. An employee has a name (a char *) , HourlyWage (float) , WorkedHours(float) and ExtraHours(float).

 

Write a function  

float  wageCalculator()  

 

that reads in the name and hourly wage of an employee. Then ask how many hours the employee worked in the past week. Be sure to accept fractional hours. Compute the pay. Any overtime work (over 40 hours per week) is paid at 150 percent of the regular wage. Print a paycheck for the employee.

 

Please enter employee's name then press Enter : Larry Bird

Please enter hourly wage then press Enter : 12.50

Please enter hours worked then press Enter: 10

 Paycheck for employee Larry Bird

 

 Hours worked: 10.0

 Hourly wage: 12.5

 Total payment: 125.0

Please enter employee's name then press Enter : Michael Jordan

Please enter hourly wage then press Enter : 10

Please enter hours worked then press Enter: 50

 Paycheck for employee Michael Jordan

 

 Hours worked: 50.0

 Hourly wage: 10.0
 

 Overtime hours: 10.0

 Overtime hourly wage: 15.0
 

 Total payment: 550.0
 

Question 6: 
 

Implement a structure Address. An address has  

•      a HouseNumber (int),  

•      a street (int),  

•      an optional ApartmentNumber (int),  

•      a city(char*),   a state(char*)  

•      PostalCode(int).  

write two constructors:  

•      one with an ApartmentNumber   and one without.  

•      Write a void print() function that prints the address with  the street on one line and the city, state, and postal code on the next line.  

•      Write a method bool compareTo() that tests whether one address comes before another when the addresses are compared by postal code

Question 7: 

Implement a structure Account. An account has data member:


•      a balance(float),  

 
and member functions  void deposit(float) add money bool withdraw(float) withdraw money after checking conditions float inquire () returns the current balance.  
 

•      Pass a value into a constructor to set an initial balance.  

•      If no value is passed the initial balance should be set to $0.  

•      Charge a $5 penalty if an attempt is made to withdraw more money than available in the account.  

Question 8 

Create a Class named Student with following private data members  

•      Roll Number(char *)

•      Name(char *)

•      Batch(int)

•      An Array named Courses_Code(int) of length 5, containing course code of the registered courses

•      An Array named Courses_Name(char *) of length 5, containing course name of the registered courses

•      An Array named Courses_Grades(char) of length 5, containing course grades of the registered courses

•      CGPA(float)

•      Degree(char *)

•      Date of Birth(char *)
 

The class should have following functions

•      setValues(), to set values of the variables

•      A default constructor to initialize all data members to some initial value

•      An overloaded constructor which is passed values of all data members as argument

•      9 different functions to update/change value of each of the data member

•      A display function to display transcript of the student in following format (including box)
 

Create an instance of the above structure in function named studentDemo void studentDemo() and demonstrate use of all member function of the structure 

Question 9: 
 

Write the definition for a class called Rectangle that has floating-point data members length and width. The class has the following member functions:
 

•      void setLength(float) to set the length data member

•      void setWidth(float) to set the width data member

•      float perimeter() to calculate and return the perimeter of the rectangle

•      float area() to calculate and return the area of the rectangle

•      void show() to display the length and width of the rectangle

•      int sameArea(Rectangle) that has one parameter of type Rectangle. sameArea() returns 1 if the two Rectangles have the same area, and returns 0 if they don't.

Question 10: 
 

Implementation of Array Class Your goal is to implement a generic “Array” class. Your implemented class must fully provide the definitions of following class (interface) functions given in the code snippets below:  

 

More products