Question

2. In the following program an employee of a company is represented by an object of type employee consisting of a name, emploMain Program Using Employee and Time Classes File: testemployeetime.cpp Application program using classes employee and time P

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

/*Test c++ program that test the employee object by creating an object of employee type and
display the employee object to console window.*/
//testemployeetime.cpp
#include<iostream>
#include "employeetime.h"
using namespace std;
int main()
{
   //create an object of employee class
   employee x("Smith", 124, 50000, 8,30);
   cout<<"x = ";
   //call write method
   x.write(cout);

   system("pause");
   return 0;
}

---------------------------------------------------------------------------------------------------------------

//employeetime header file

//employeetime.h
#ifndef EMPLOYEETIME_H
#define EMPLOYEETIME_H
#include<iostream>
#include<string>
using namespace std;
class time24
{
private:
   int hour;
   int minute;
public:
   //time24 constructor declaration
   time24(int h , int m);
   void write(ostream & out) const;
};
//employee class
class employee
{
private:
   string name;
   int id;
   float salary;
   time24 start;
public:
   //employee constructor declaration
   employee(string n, int i, float s, int h, int m);
   void write(ostream & out) const;
};
#endif EMPLOYEETIME_H

---------------------------------------------------------------------------------------------------------------

//employeetime implementation file

//employeetime.cpp
//include employeetime.h header file
#include "employeetime.h"
/*constructor that takes h and m input
arguments and set h and m to hour and minute */
time24::time24(int h , int m)
{
   hour=h;
   minute=m;
}
/*write method that display the time in
hour and minutes*/

void time24::write(ostream & out) const
{
   out<<hour/10<<hour%10<<":"
       <<minute/10<<minute%10;
}

/*employee constructor
pass arguments h and m to time24 object,start
in the header declartion itself
*/

employee::employee(string n, int i, float s, int h, int m)
   :start(h,m)
{
   name=n;
   id=i;
   salary=s;
}
/*write method to display the employee details
along with time */
void employee::write(ostream & out) const
{
   out<<"{"<<name<<", "<<id<<", "<<salary<<", ";
   start.write(out);
   out<<"}";
}

---------------------------------------------------------------------------------------------------------------

Sample Output:

x = {Smith, 124, 50000, 08:30}F

Add a comment
Know the answer?
Add Answer to:
2. In the following program an employee of a company is represented by an object of...
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
  • Write the functions needed to complete the following program as described in the comments. Use the...

    Write the functions needed to complete the following program as described in the comments. Use the input file course.txt and change the mark of student number 54812 to 80. /* File: course.cpp A student's mark in a certain course is stored as a structure (struct student as defined below) consisting of first and last name, student id and mark in the course.  The functions read() and write() are defined for the structure student.   Information about a course is stored as a...

  • BACKGROUND Movie Review sites collect reviews and will often provide some sort of average review to...

    BACKGROUND Movie Review sites collect reviews and will often provide some sort of average review to sort movies by their quality. In this assignment, you will collect a list of movies and then a list of reviews for each movie. You will then take a simple average (total of reviews divided by number of reviews) for each movie and output a sorted list of movies with their average review. Here you are provided the shell of a program and asked...

  • This is for my c++ class and im stuck. Complete the Multiplex.cpp file with definitions for a fun...

    This is for my c++ class and im stuck. Complete the Multiplex.cpp file with definitions for a function and three overloaded operators. You don't need to change anything in the Multiplex.h file or the main.cpp, though if you want to change the names of the movies or concession stands set up in main, that's fine. Project Description: A Multiplex is a complex with multiple movie theater screens and a variety of concession stands. It includes two vectors: screenings holds pointers...

  • I need help with the code below. It is a C program, NOT C++. It can...

    I need help with the code below. It is a C program, NOT C++. It can only include '.h' libraries. I believe the program is in C++, but it must be a C program. Please help. // // main.c // float_stack_class_c_9_29 // // /* Given the API for a (fixed size), floating point stack class, write the code to create a stack class (in C). */ #include #include #include #include header file to read and print the output on console...

  • Instructions: Consider the following C++ program. At the top you can see the interface for the...

    Instructions: Consider the following C++ program. At the top you can see the interface for the Student class. Below this is the implementation of the Student class methods. Finally, we have a very small main program. #include <string> #include <fstream> #include <iostream> using namespace std; class Student { public: Student(); Student(const Student & student); ~Student(); void Set(const int uaid, const string name, const float gpa); void Get(int & uaid, string & name, float & gpa) const; void Print() const; void...

  • Write a C++ Program. You have a following class as a header file (dayType.h) and main()....

    Write a C++ Program. You have a following class as a header file (dayType.h) and main(). #ifndef H_dayType #define H_dayType #include <string> using namespace std; class dayType { public:     static string weekDays[7];     void print() const;     string nextDay() const;     string prevDay() const;     void addDay(int nDays);     void setDay(string d);     string getDay() const;     dayType();     dayType(string d); private:     string weekDay; }; #endif /* // Name: Your Name // ID: Your ID */ #include <iostream>...

  • This is assignment and code from this site but it will not compile....can you help? home...

    This is assignment and code from this site but it will not compile....can you help? home / study / engineering / computer science / computer science questions and answers / c++ this assignment requires several classes which interact with each other. two class aggregations ... Question: C++ This assignment requires several classes which interact with each other. Two class aggregatio... (1 bookmark) C++ This assignment requires several classes which interact with each other. Two class aggregations are formed. The program...

  • The task is to write Song.cpp to complete the implementation of the Song class, as defined...

    The task is to write Song.cpp to complete the implementation of the Song class, as defined in the provided header file, Song.h, and then to complete a program (called sales) that makes use of the class. As in Project 1, an input data file will be provided containing the song name and other information in the same format as in Program 1: Artist    Song_Title    Year    Sales    Medium As before, the program (sales) which are individual copies, will use this information to compute the gross...

  • The 4th deliverable is to create the program the makes the buy recommendation. It uses the...

    The 4th deliverable is to create the program the makes the buy recommendation. It uses the class Stock to store and retrieve the stock information. I need to make this program compatible with my stocks class. Program I need to change: #include <iostream> #include <cmath> #include <fstream> #include <iomanip> #include <string> #include <stdlib.h> using namespace std; // read the data file, store in arrays int openDatafile(ifstream&,string [], float[], float[], int[]); // opens the data file void readData(ifstream &, string[], float[],...

  • C++ Program 2 Consider a class Employee with data members: age (an integer), id (an integer)...

    C++ Program 2 Consider a class Employee with data members: age (an integer), id (an integer) and salary (a float), and their corresponding member functions as follows: class Employee { private: int age; int id; float salary: public: Employee; // default constructor: age=0, id=0, and salary=0 void setAge(int x); // let age = x void setId(int x); // let id = x void setSalary(float x); // salary = x int getAge(); // return age int getId; // return id float...

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