Question

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 identification number. These values should be assign to the object’s memberName and memberID data members. The constructor should also assign 0 to numBooks and purchaseAmt.

Accessor. Appropriate accessor function to get the values stored in an object’s memberName, memberID, numBooks, and purchaseAmt data members.

addNewPurchase. The addNewPurchase function should accept the number of books for a new purchase and the total amount of the purchase in dollars. The function should add these values to the existing numBooks and purchaseAmt data member.

Demonstrate the class in a client program that creates a memberType object and then calls the addNewPurchase function twice (representing 2 new purchases). After each new purchase, display the member’s id and name along with the current number of books and current purchase amount.

Documentation (10%)

program file name

brief description of assignment

name of the author

course title and meeting time

assignment number and due date

each function has a brief description

Formatting (10%)

Use proper indentation in main function

Use proper indentation for function declarations

Technique (40%)

Identifiers have meaningful names

memberType.h file contains correct data members

memberType class contains required constructor

memberType class file contains required accessor functions

memberType class file contains required addNewPurchase function

Main function creates a "memberType" object and tests all accessor functions and the addNewPurchase function

Output (40%)

Program runs without modification

In client program identification number of the person of "memberType" object is displayed using accessor function

In client program name of the person of the"memberType" object is displayed using accessor function

In client program number of books of the"memberType" object is displayed using accessor function

In client program purchase amoutn of the "memberType" object is displayed using accessor function

The appropriate member information is displayed after each call to the addNewPurchase function

Late (5% per day)

  100%%

TOTAL

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

Please prepare the documentation items (name of auther, course title and meeting time, etc.) as mentioned in the assignment details. Please find the code details below. The code has been appropriately commented as asked in the assignment.

memberType.h

This contains the class definition for the memberType class as asked in the assignment.

#include<string>

using namespace std;

class memberType

{

          private:

          // name of the member

          string memberName;

         

          // ID of the member

          string memberId;

         

          // Number of books bought

          int numBooks;

         

          // The amount spent on books

          double purchaseAmt;

         

          public:

                   

          // The constructor for the class

          memberType(string memberName, string memberId)

          {

                    this->memberName = memberName;

                    this->memberId = memberId;

                    this->numBooks = 0;

                    this->purchaseAmt = 0.0;

          }

         

          // Get the name of the member

          string getMemberName()

          {

                    return this->memberName;

          }

          // Get the member ID

          string getMemberId()

          {

                    return this->memberId;

          }

         

          // Get the number of books

          int getNumBooks()

          {

                    return this->numBooks;

          }

         

          // Get the purchase amount

          double getPurchaseAmt()

          {

                    return this->purchaseAmt;

          }        

         

          // Add a new purchase

          void addNewPurchase(int numBooksForPurchase, double totalAmountOfPurchase)        

          {

                    this->numBooks += numBooksForPurchase;

                    this->purchaseAmt += totalAmountOfPurchase;

          }

};

memberTypeClient.cpp

This is the client application and uses the class created in the header file

#include<iostream>

#include<string>

#include "memberType.h"

using namespace std;

// The main method for the client application

int main()

{

          // Create the new member type giving the name and the ID

          memberType m("Example Member", "MEM001");

         

          // First purchase

          m.addNewPurchase(5, 100);

          cout<<" Member ID: "<<m.getMemberId()<<" Member Name: "<<m.getMemberName()<<" Current Number of books: "<<m.getNumBooks()<<" Current purchase amount: "<<m.getPurchaseAmt()<<"\n";

         

          // Second purchase

    m.addNewPurchase(10, 200);

          cout<<" Member ID: "<<m.getMemberId()<<" Member Name: "<<m.getMemberName()<<" Current Number of books: "<<m.getNumBooks()<<" Current purchase amount: "<<m.getPurchaseAmt()<<"\n";

          return 0;

}

Add a comment
Know the answer?
Add Answer to:
C++ Programing In this exercise, you will design a class memberType. The class has the following...
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
  • In C++, Step 1: Implement the Student Class and write a simple main() driver program to...

    In C++, Step 1: Implement the Student Class and write a simple main() driver program to instantiate several objects of this class, populate each object, and display the information for each object. The defintion of the student class should be written in an individual header (i.e. student.h) file and the implementation of the methods of the student class should be written in a corresponding source (i.e. student.cpp) file. Student class - The name of the class should be Student. -...

  • C++ Program 1a. Purpose Practice the creation and use of a Class 1b. Procedure Write a...

    C++ Program 1a. Purpose Practice the creation and use of a Class 1b. Procedure Write a class named Car that has the following member variables: year. An int that holds the car’s model year. make. A string object that holds the make of the car. speed. An int that holds the car’s current speed. In addition, the class should have the following member functions. Constructor. The constructor should accept the car’s year and make as arguments and assign these values...

  • Please help with this assignment. Thanks. 1. Write a C++ program containing a class Invoice and...

    Please help with this assignment. Thanks. 1. Write a C++ program containing a class Invoice and a driver program called invoiceDriver.cpp. The class Invoice is used in a hardware store to represent an invoice for an item sold at the store. An invoice class should include the following: A part number of type string A part description of type string A quantity of the item being purchased of type int A price per item of type int A class constructor...

  • 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...

  • Write a C++ program Write a class named Employee that has the following member variables: name...

    Write a C++ program Write a class named Employee that has the following member variables: name A string that holds the employee name idNumber An int to hold employee id number department A string to hold the name of the department position A string to hold the job position The class will have three constructors: 1. A constructor that accepts all the internal data such as: Employee susan("Susan Meyers", 47899, "Accounting", "Vice President"); 2. A constructor that accepts some of...

  • Design a class named Month. The class should have the following private members:

    Design a class named Month. The class should have the following private members:   • name - A string object that holds the name of a month, such as "January", "February", etc.   • monthNumber - An integer variable that holds the number of the month. For example, January would be 1, February would be 2, etc. Valid values for this variable are 1 through 12.  In addition, provide the following member functions:• A default constructor that sets monthNumber to 1 and name...

  • Using C++, Write a class named Employee that has the following member variables: name. A string...

    Using C++, Write a class named Employee that has the following member variables: name. A string that holds the employee's name. idNumber. An int variable that holds the employee's ID number. department. A string that holds the name of the department where the employee works. position. A string that holds the employee's job title. The class should have the following constructors: A constructor that accepts the following values as arguments and assigns them to the appropriate member variables: employee's name,...

  • C++ Assignment: Create a class called FitnessMember that has only one variable, called name. The FitnessMember...

    C++ Assignment: Create a class called FitnessMember that has only one variable, called name. The FitnessMember class should have a constructor with no parameters, a constructor with a parameter, a mutator function and an accessor function. Also, include a function to display the name. Define a class called Athlete which is derived from FitnessMember. An Athlete record has the Athlete's name (defined in the FitnessMember class), ID number of type String and integer number of training days. Define a class...

  • It must be C++ Chapter 13 Programming Challenge 2: Employee Class. See instruction: Chapter 13 Programming...

    It must be C++ Chapter 13 Programming Challenge 2: Employee Class. See instruction: Chapter 13 Programming Challenge 2 Employee Class.pdf Program Template: // Chapter 13, Programming Challenge 2: Employee Class #include <iostream> #include <string> using namespace std; // Employee Class Declaration class Employee { private: string name; // Employee's name int idNumber; // ID number string department; // Department name string position; // Employee's position public: // TODO: Constructors // TODO: Accessors // TODO: Mutators }; // Constructor #1 Employee::Employee(string...

  • 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...

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