Question

Objective: The purpose of this lab project is to expose you to structures and classes. Problem...

Objective:

The purpose of this lab project is to expose you to structures and classes.

Problem Specification:

You are to write a program that will define a structure consisting of the following data members, “fields”:

  • name
  • hours worked
  • hourly rate
  1. Use a structure to implement the following:

You will use a function to read the name, hours and rate, passing them individually by reference to the main function.

Call a function to print, this function accepts the entire structure by value.

This function will call a function that will return the grosspay, a local variable in print, by multiplying the hours times the rate.

The function then prints each data member on a separate line followed by the grosspay.

  1. Use a class to implement the same problem solution:

Data members are the specified above, no other data members.

You must include a null constructor, and destructor.

You must not use inline function, must declare functions in the class declaration section, and then implement them.

A member function prints the information (all data members, each on a separate line) calls the function that calculates the grosspay, not a data member, and prints the grosspay.

The function that calculates the grosspay must be private.

Input to the program consists of:

  • name
  • hours worked
  • hourly rate

Your output should be a report like follows:

Employee Name:        Jim Donavan

Hours worked:                                                 40.00

Hourly Rate:                                              $     9.75

Wages:                                                          $ 390.00

Grading criteria:

          Structure implementation

10 points         Good programming practices:

Descriptive names are used

Proper spacing, comments, use of variables.

Indentation and appearance of program.

5 points         structure defined correctly with the specified data members.

5 points         Hierarchical chart is handed-in and is correct.

10 points         the function that reads the data passes the values entered back into the structure.

5 points         the function that calculates, returns the gross as its value.

10 points         the function that prints accepts the entire structures value, prints all the members on a separate line each and the grosspay.

5 points         test results for the structure implementation are handed in.

Class Implementation

5   points       class is defined correctly (data members, member functions).

5   points       UML class diagram is handed-in and is correct.

5 points         constructor and destructor functions are defined and are null.

5 points         main instantiate objects and calls public functions to do tasks.

10 points         a member function reads the input data.

10 points         the print member function done correctly and does what it supposed to.

5 points         the function to find the gross is private correct and is called from print.

5 points         test results for the class implementation are handed in.

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

Structure implementation

#include <iostream>
#include <string>

using namespace std;

struct Employee
{
int hours_worked;
string name;
float hourly_rate;
};


//accepts reference variable so that read inputs are reflected back
void read (struct Employee &emp)
{
  
cout<<endl<<"Enter name :";
cin>>emp.name;
cout<<endl<<"Hours worked :";
cin>>emp.hours_worked;
cout<<endl<<"Hourly rate : ";
cin>>emp.hourly_rate;
  
}


double pay(int hr, double rate){
return hr*rate;
}

//pass by value
void print(struct Employee emp){
double grosspay;
grosspay = pay(emp.hours_worked,emp.hourly_rate);
cout<<endl<<"Employee Name : "<<emp.name;
cout<<endl<<"Hours Worked : "<<emp.hours_worked;
cout<<endl<<"Hourly Rate : $"<<emp.hourly_rate;
cout<<endl<<"Gross Pay : $"<<grosspay;
}


int main()
{
   struct Employee emp;
read(emp);
print(emp);
   return 0;
}

class implementation

#include <iostream>

#include <string>

using namespace std;

class Employee

{

private:

int hours_worked;

string name;

float hourly_rate;

//private pay

void pay();

public:

//constructor

Employee(){}

//function declare

void read();

void print();

//destuctor

~Employee(){}

};


//definition

void Employee:: read ()

{

cout<<endl<<"Enter name :";

cin>>name;

cout<<endl<<"Hours worked :";

cin>>hours_worked;

cout<<endl<<"Hourly rate : ";

cin>>hourly_rate;

}


void Employee::pay(){

double grosspay = hours_worked * hourly_rate;

cout<<endl<<"Gross Pay : $"<<grosspay;

}

//pass by value

void Employee::print(){

cout<<endl<<"Employee Name : "<<name;

cout<<endl<<"Hours Worked : "<<hours_worked;

cout<<endl<<"Hourly Rate : $"<<hourly_rate;

pay();

}


int main()

{

  Employee emp;

emp.read();

emp.print();

  return 0;

}

output

Add a comment
Know the answer?
Add Answer to:
Objective: The purpose of this lab project is to expose you to structures and classes. Problem...
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
  • problem specification: writing in c++ language ... Question Problem Specification: Writing in c++ language write a...

    problem specification: writing in c++ language ... Question Problem Specification: Writing in c++ language write a program that will define a structure consisting of the following data members, “fields”: - name - hours worked - hourly rate Use a structure to implement the following: -Use a function to read the name, hours and rate, passing them by reference to the main function. -Call a function to print, this function accepts the entire structure by value. This function will call a...

  • About Classes and OOP in C++ Part 1 Task 1: Create a class called Person, which...

    About Classes and OOP in C++ Part 1 Task 1: Create a class called Person, which has private data members for name, age, gender, and height. You MUST use this pointer when any of the member functions are using the member variables. Implement a constructor that initializes the strings with an empty string, characters with a null character and the numbers with zero. Create getters and setters for each member variable. Ensure that you identify correctly which member functions should...

  • Project 3 Objective: The purpose of this lab project is to exposes you to using menus,...

    Project 3 Objective: The purpose of this lab project is to exposes you to using menus, selection writing precise functions and working with project leaders. Problem Specification: The PCCC Palace Hotel needs a program to compute and prints a statement of charges for customers. The software designer provided you with the included C++ source and you are asked to complete the code to make a working program using the given logic. The function main () should not change at all....

  • Design a PayRoll class that has data members for an employee’s first and last name, hourly...

    Design a PayRoll class that has data members for an employee’s first and last name, hourly pay rate, number of hours worked. The default constructor will set the first and last name to empty string, and hours worked and pay rate to zero. The class must have mutator functions to set each of the data members of the class and accessors to access them. The class should also have the following member functions: displayPayroll function that displays all data members...

  • in c++ Define and implement the class Employee with the following requirements: private data members string...

    in c++ Define and implement the class Employee with the following requirements: private data members string type name a. b. double type hourlyRate 2. public member functions a. default constructor that sets the data member name to blank"and hourlyRate to zero b. A constructor with parameters to initialize the private data members c. Set and get methods for all private data members d. A constant method weeklyPay() that receives a parameter representing the number of hours the employee worked per...

  • Create a class hierarchy to be used in a university setting. The classes are as follows:...

    Create a class hierarchy to be used in a university setting. The classes are as follows: The base class is Person. The class should have 3 data members: personID (integer), firstName(string), and lastName(string). The class should also have a static data member called nextID which is used to assign an ID number to each object created (personID). All data members must be private. Create the following member functions: o Accessor functions to allow access to first name and last name...

  • Objectives: 1. Classes and Data Abstraction?2. User-defined classes?3. Implementation of a class in separate files Part...

    Objectives: 1. Classes and Data Abstraction?2. User-defined classes?3. Implementation of a class in separate files Part 1: In this assignment, you are asked: Stage1:?Design and implement a class named memberType with the following requirements: An object of memberType holds the following information: • Person’s first name (string)?• Person’s last name (string)?• Member identification number (int) • Number of books purchased (int)?• Amount of money spent (double)?The class memberType has member functions that perform operations on objects of memberType. For the...

  • Objective: Learn how to -- read string from a file -- write multiple files Problem: Modify...

    Objective: Learn how to -- read string from a file -- write multiple files Problem: Modify the Person class in Lab #4. It has four private data members firstNam (char[20]), day, month, year (all int); and two public member functions: setPerson(char *, int, int, int) and printInfo(). The function setPerson sets the first name and birthday in the order of day, month and year. The function printInfo prints first name and birthday. But it should print the date in the...

  • Purpose: Demonstrate the ability to create and manipulate classes, data members, and member functions. This assignment...

    Purpose: Demonstrate the ability to create and manipulate classes, data members, and member functions. This assignment also aims at creating a C++ project to handle multiple files (one header file and two .cpp files) at the same time. Remember to follow documentation and variable name guidelines. Create a C++ project to implement a simplified banking system. Your bank is small, so it can have a maximum of 100 accounts. Use an array of pointers to objects for this. However, your...

  • (1) Please i need good explanation to this problem thnks. private members are name(string), year(int), passenger(int),...

    (1) Please i need good explanation to this problem thnks. private members are name(string), year(int), passenger(int), passenger(int), and maker(string). Assume that all kinds of constructors, destructor, mutators and accessor member functions are defined correctly. 1). for the Car class, define the overloading cout's stream insertion operator function should cause all private members to be displayed well-format form.

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