Question

C++ design a class named Technician that contains private data members to store the following: -technician's...

C++

design a class named Technician that contains private data members to store the following:

-technician's name (a string)

- number of service calls

- total time of all service calls

- average service call time

the technician class should also have the following public member functions:

- a constructor function that initializes all data members by obtaining their values from the users.

with the exception of the average service call time which will be calculated as: total_time/number_of_call

- a function that returns the technician's name

- a function that return the average time

- a non-inline member function that displays the technician's data,i.e. definition of this function is placed of the class.

The program should create as many technician objects as requested by the user. a dynamic array of technician objects.

It is required to check for and handle the memory allocation errors. the program will first obtain all technician's data from the user by using the constructor function. it will then display all technician's data and compute which technician has the HIGHEST average service call time. A sample of the program output could be as follows:

Technician       Number of calls        Total time         Average time(min)

Joe Smart        12                             74                     6.17

Mike Smith        9                              83                     9.22

Jenny Yo            10                             78                    7.80

The highest average service call time: Mike Smith = 9.22 min.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you have any doubts, please give me comment...

#include <iostream>

#include <iomanip>

#include <string>

using namespace std;

class Technician

{

public:

    Technician(){}

    Technician(string _name, int no_calls, int tot_time)

    {

        name = _name;

        no_service_calls = no_calls;

        total_time = tot_time;

        try

        {

            if (no_service_calls == 0)

                throw "Division by zero condition!";

            avg_service_call_time = (double)total_time / no_service_calls;

        }

        catch (const char *msg)

        {

            cerr << msg << endl;

        }

    }

    string getName() const{

        return name;

    }

    double getAverageTime(){

        return avg_service_call_time;

    }

    void display();

private:

    string name;

    int no_service_calls;

    int total_time;

    double avg_service_call_time;

};

void Technician::display(){

    cout<<setw(20)<<name<<setw(20)<<no_service_calls<<setw(15)<<total_time<<"\t"<<avg_service_call_time<<endl;

}

int main()

{

    int n;

    cout<<"Enter how many technicians would you like: ";

    cin>>n;

    Technician *tech = new Technician[n];

    string name;

    int no_calls, tot_mins;

    for(int i=0; i<n; i++){

        cout<<"Enter technician"<<(i+1)<<" name: ";

        getline(cin, name);

        getline(cin, name);

        cout<<"Enter Number of calls: ";

        cin>>no_calls;

        cout<<"Enter total time: ";

        cin>>tot_mins;

        tech[i] = Technician(name, no_calls, tot_mins);

    }

    cout<<endl;

    cout<<setprecision(2)<<fixed;

    cout<<setw(20)<<left<<"Technician"<<setw(20)<<"Number of calls"<<setw(15)<<"Total time"<<"\tAverage time(min)"<<endl;

    int highest_ind = 0;

    for(int i=0; i<n; i++){

        tech[i].display();

        if(tech[highest_ind].getAverageTime()<tech[i].getAverageTime()){

            highest_ind = i;

        }

    }

    cout<<"The highest average service call time: "<<tech[highest_ind].getName()<<" = "<<tech[highest_ind].getAverageTime()<<" min."<<endl;

    delete[] tech;

    return 0;

}

Add a comment
Know the answer?
Add Answer to:
C++ design a class named Technician that contains private data members to store the following: -technician's...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Construct a C++ class named Rectangle that has floating-point data members named length and width.  The class...

    Construct a C++ class named Rectangle that has floating-point data members named length and width.  The class should have a zero-argument constructor that initializes each data member to 0. It should have member functions named calcPerimeter() and calcArea() that calculate the perimeter and area of a rectangle respectively, a member function setLength() and setWidth() to set the length and width, member functions getLength() and getWidth() to return the length and width, and a member function showData() that displays the rectangle’s length,...

  • Which of the following statements is true about data members of a class definition? Data members...

    Which of the following statements is true about data members of a class definition? Data members are set in the constructor and cannot be changed later. Every object of the defined class has its own set of data members, with possibly different values. All data members are shared by all objects of the defined class. The value stored in a data member can be changed by any function in the program.

  • (Classes and Objects) Design a class named Box. The class should have the following private members:...

    (Classes and Objects) Design a class named Box. The class should have the following private members: width - A double member variablethat holds the width of the box. length – A double member variable for holding the length of the box. height – A double member variable of type double that holds the height of the box. In addition, provide the following member functions with full (inline) implementation. a) A default constructor that sets all member variables to 0. b)...

  • Define a class named COMPLEX for complex numbers, which has two private data members of type...

    Define a class named COMPLEX for complex numbers, which has two private data members of type double (named real and imaginary) and the following public methods: 1- A default constructor which initializes the data members real and imaginary to zeros. 2- A constructor which takes two parameters of type double for initializing the data members real and imaginary. 3- A function "set" which takes two parameters of type double for changing the values of the data members real and imaginary....

  • C++ Programing In this exercise, you will design a class memberType. The class has the following...

    C++ Programing In this exercise, you will design a class memberType. The class has the following data members: memberName. A string that holds the name of a person memberID. A string that holds the member identification number numBooks. An int that holds the number of books bought purchaseAmt. A double that holds the amount spent on books In addition, the class should have the following constructor and other member functions. Constructor. The constructor should accept the person’s name and member...

  • Write a C++ class named CashRegister. The class should have private data members named Hundreds, Tens,...

    Write a C++ class named CashRegister. The class should have private data members named Hundreds, Tens, Fives, and Singles all of type integer. The class should have the following: 1. A member function named GetTotalCash to retrieve the total cash inside the cash register. 2. Overload the + operator to allow adding two objects of type CashRegister (note, add the hundreds to the hundreds, tens to tens and so on). 3. Overload the > operator to compare between two CashRegisters...

  • Overloading Design a UML diagram for a TimeClock class with the following private data members: •...

    Overloading Design a UML diagram for a TimeClock class with the following private data members: • float days • float hours The class should also have the following public member methods: • Constructor with a default that sets the data values to 0 • getDays to return the private data member days • getHours to return the private data member hours • setDays to set the private data member days • setHours to set the private data member hours •...

  • C++ program Create a class Time having data members HH, MM, SS of type integer. Write...

    C++ program Create a class Time having data members HH, MM, SS of type integer. Write a C++ program to do the following: 1. Use a Constructor to initialize HH, MM, SS to 0. 2. Create two Objects of this class and read the values of HH, MM, SS from the user for both objects (Using proper member functions). 3. Use a binary + operator to add these two objects created (Store & display result using separate object). 4. Use...

  • Construct a class named Fractions containing two integer data members named num and denom, used to...

    Construct a class named Fractions containing two integer data members named num and denom, used to store the numerator and denominator of a fraction having the form num/denom. Your class should include a default constructor that initializes num and denom to 1 if there's no user initialization, and it must prohibit a 0 denominator value. In addition, create member functions for displaying an object's data values and overloaded operator functions for adding, subtracting, multiplying, and dividing two Fraction objects, as...

  • Write a class named RowSort which has the following members. Private: (1) double matrix 0O (a...

    Write a class named RowSort which has the following members. Private: (1) double matrix 0O (a 2D array): (2) int columns; (3) int rows Public: (1) A default constructor that creates a 2D array, 8 6 4 (2) A constructor that takes three values for the three private members, and creates a 2D array accordingly. (3) The "get" and "set" methods for the three private members. (4) A method that displays a 2D array, stored in the private member matrix,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT