Question

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 mentioned pieces of data that an object of memberType has (first name, last name,?id, number of books purchased, money spent), there are member functions for setting, retrieving, and printing each of these values:

            (functions) for first name, last name, id, book purchased, and money spent. ?

            (functions) for first name, last name, id, book purchased, and money spent. ?

            function) prints first name, last name, Number of book purchased, and money spent. ?

            function. (it sets string variables to empty and integer and double variables to 0) ?Stage2: ?Define the functions bodies of the class memberType. Stage3: ?Use the following code as your driver program to test various operations of the class memberType such that it produces exact output as provided. ?

Output:

Objectives: 1. Classes and Data Abstraction

Additional requirements:

Use one source (.cpp) file for Question1

Comment your work. Also, put your name and lab number and question number on top of your(.cpp) file.

Part 2:

Stage1: Use question 1 and separate it into files for implementing the class (header file), defining the functions of the class (cpp file that maps to the header file), and testing the class by a driver program (cpp file with the main function).

Stage2: Add these extra functionalities to the memberType class and complete their functions.

Parameterized Constructor: It creates a new object and sets values for all member variables. ?

equal function: It compares the current object with another object, returns true if they are the same. ?

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

Answer: Part1: nember Type.h: #include<string> using namespace stdi class memberType rivate: string firstName: string lastNaminemberType.cpp #include<iostream> #include memberType.h using namespace stdi memberType: :memberType O this-lastName this-void memberType: :setFirstName (string fname) this->firstName void memberType::setLastName (string lname) fname ; = this-lastMain.cpp: #include <iostream» #include£8stream> # include<string> # include memberType.h using namespace std; int main () mOutput: users12034831documentslvisual studio 20151Projects Project78 DebuglProject78.exe MemberInfo: San Fire Numbe of booksPart2: membeiType.h: # include<string> using namespace std: class memberType private: string firstName: string lastName: intmemberType:memberType this->firstName = ; this->lastName this->books this->money 0; 0.0; = = memberType::memberTvpe (stringvoid memberType::printMember () cout < MemberInfo:< firstName <<<< cout Number of books Purchased: coutK Spent Amount:cout< endl; 1 f (member2. egual (member3 ) ) coutK Member 2 and 3 are equal << endl: else coutK Member 2 and 3 are unequalcopyable code:

Part1:

memberType.h:

#include<string>

using namespace std;

class memberType

{

private:

             string firstName;

             string lastName;

             int id;

             int books;

             double money;

public:

             memberType();

             void setLastName(string);

             void setFirstName(string);

             void setId(int);

             void setbooksPurchased(int);

             void setAmountSpent(double);

             string getLastName();

             string getFirstName();

             int getId();

             int getbooksPurchased();

             double getAmountSpent();

             void printMember();

};

memberType.cpp:

#include<iostream>

#include "memberType.h"

using namespace std;

memberType::memberType()

{

             this->lastName = "";

             this->id = 0;

             this->books = 0;

             this->money = 0.0;

}

string memberType::getFirstName()

{

             return this->firstName;

}

string memberType::getLastName()

{

             return this->lastName;

}

int memberType::getId()

{

             return this->id;

}

int memberType::getbooksPurchased()

{

             return this->books;

}

double memberType::getAmountSpent()

{

             return this->money;

}

void memberType::setFirstName(string fname)

{

             this->firstName = fname;

}

void memberType::setLastName(string lname)

{

             this->lastName = lname;

}

void memberType::setId(int id)

{

             this->id = id;

}

void memberType::setbooksPurchased(int bookpurchased)

{

             this->books = bookpurchased;

}

void memberType::setAmountSpent(double amount)

{

             this->money = amount;

}

void memberType::printMember()

{

cout << "MemberInfo: " << getFirstName() << " " << getLastName() << endl;

cout << "Number of books Purchased: " << getbooksPurchased() << endl;

cout << "Spent Amount: " << getAmountSpent() << "$" << endl;

}

Main.cpp:

#include <iostream>

#include<sstream>

#include<string>

#include"memberType.h"

using namespace std;

int main()

{

             memberType member1;

             member1.setFirstName("Sam");

             member1.setLastName("Fire");

             member1.setId(100);

             member1.setAmountSpent(105.39);

             member1.setbooksPurchased(3);

             member1.printMember();

             cout << endl;

             memberType member2;

             member2.setFirstName("Sarah");

             member2.setLastName("Johns");

             member2.setId(101);

             member2.setAmountSpent(263.81);

             member2.setbooksPurchased(6);

             member2.printMember();

            

             system("pause");

             return 0;

}

Part2:

memberType.h:

#include<string>

using namespace std;

class memberType

{

private:

             string firstName;

             string lastName;

             int id;

             int books;

             double money;

public:

             memberType();

             memberType(string,string,int,int,double);

             bool equal(memberType);

             void printMember();

};

memberType.cpp:

#include<iostream>

#include "memberType.h"

using namespace std;

memberType::memberType()

{

             this->firstName = "";

             this->lastName = "";

             this->id = 0;

             this->books = 0;

             this->money = 0.0;

}

memberType::memberType(string fname,string lname,int ID,int Nbook,double amt)

{

             this->firstName = fname;

             this->lastName = lname;

             this->id = ID;

             this->books = Nbook;

             this->money = amt;

}

bool memberType::equal(memberType m)

{

             if (this->firstName.compare(m.firstName) == 0)

              if (this->lastName.compare(m.lastName) == 0)

                   if (this->id == m.id)

                        if (this->books == m.books)

                             if (this->money == m.money)

                                  return true;

                             else return false;

                        else return false;

                   else return false;

              else return false;

             else return false;

}

void memberType::printMember()

{

             cout << "MemberInfo: " << firstName << " " << lastName << endl;

             cout << "Number of books Purchased: " << books << endl;

             cout << "Spent Amount: " << money<< "$" << endl;

}

Main.cpp:

#include <iostream>

#include<sstream>

#include<string>

#include"memberType.h"

using namespace std;

int main()

{

             memberType member1("Sam","Fire",100,3,105.39);

             member1.printMember();

             cout << endl;

memberType member2("Sarah", "Johns", 101, 6, 263.81);

             member2.printMember();

             cout << endl;

             if (member1.equal(member2))

              cout << "Member 1 and 2 are equal" << endl;

             else

             cout << "Member 1 and 2 are unequal" << endl;

             cout << endl;

memberType member3("Sarah", "Johns", 101, 6, 263.81);

             member3.printMember();

             cout << endl;

             if (member2.equal(member3))

              cout << "Member 2 and 3 are equal" << endl;

             else

              cout << "Member 2 and 3 are unequal" << endl;

             system("pause");

             return 0;

}

Add a comment
Know the answer?
Add Answer to:
Objectives: 1. Classes and Data Abstraction?2. User-defined classes?3. Implementation of a class in separate files Part...
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
  • 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...

  • The class declaration (interface) and the function definitions (implementation) must be in separate files - the...

    The class declaration (interface) and the function definitions (implementation) must be in separate files - the interface or "header" file has a .hpp extension and the implementation has a .cpp extension. As usual, all data members should be private. Write a class called BankAccount that has: a string data member called customerName, a string data member called customerID, and a double data member called customerBalance a constructor that takes two strings and a double (name, ID, balance) and uses them...

  • Implement the following class in interface and implementation files. A separate file (the main project file)...

    Implement the following class in interface and implementation files. A separate file (the main project file) shall have the main function that exercises this class. Create a class named Student that has three member variables: name - string that stores the name of the student numClasses - integer that tracks how many courses the student is currently enrolled in, this number must be between 1 and 100 ClassList - an array of strings of size 100 used to store the...

  • Part (A) Note: This class must be created in a separate cpp file Create a class...

    Part (A) Note: This class must be created in a separate cpp file Create a class Employee with the following attributes and operations: Attributes (Data members): i. An array to store the employee name. The length of this array is 256 bytes. ii. An array to store the company name. The length of this array is 256 bytes. iii. An array to store the department name. The length of this array is 256 bytes. iv. An unsigned integer to store...

  • 1) This exercise is about Inheritance (IS-A) Relationship. A) First, draw the UML diagram for class...

    1) This exercise is about Inheritance (IS-A) Relationship. A) First, draw the UML diagram for class Student and class ComputerSystemsStudent which are described below. Make sure to show all the members (member variables and member functions) of the classes on your UML diagram. Save your UML diagram and also export it as a PNG. B) Second, write a program that contains the following parts. Write each class interface and implementation, in a different .h and .cpp file, respectively. a) Create...

  • 1a. Create a class named Computer - Separate declaration from implementation (i.e. Header and CPP files)...

    1a. Create a class named Computer - Separate declaration from implementation (i.e. Header and CPP files) 1b. Add the following private member variables - an int variable named year - a string variable named model - a string variable named purpose 1c Add the following public functions: - Default constructor which sets numeric members to -1 and string members to the empty string - Destructor to print "Removing instance from memory" - A non-default constructor to set the year and...

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

  • Redefining Base Functions (C++) Create two simple C++ classes (Use separate files please and include appropriate...

    Redefining Base Functions (C++) Create two simple C++ classes (Use separate files please and include appropriate headers) Define a base class named "Venue" that holds the following member variables and functions: Type of venue (string), e.g. public venue, private venue, community venue Year opened (int) Capacity (int) Base price (float), holds the average ticket price for the venue Potential revenue (float), a function returning capacity * base price Next, define a class named "Theater" that is derived from the "Venue"...

  • C++ program, item.cpp implementation. Implementation: You are supposed to write three classes, called Item, Node and In...

    C++ program, item.cpp implementation. Implementation: You are supposed to write three classes, called Item, Node and Inventory respectively Item is a plain data class with item id, name, price and quantity information accompanied by getters and setters Node is a plain linked list node class with Item pointer and next pointer (with getters/setters) Inventory is an inventory database class that provides basic linked list operations, delete load from file / formatted print functionalities. The majority of implementation will be done...

  • 1a. Create a class named Inventory - Separate declaration from implementation (i.e. Header and CPP files)...

    1a. Create a class named Inventory - Separate declaration from implementation (i.e. Header and CPP files) 1b. Add the following private member variables - a int variable named itemNumber - an int variable named quantity - a double variable named cost - a double variable named totalCost. Total cost is defined as quantity X cost. - updateTotalCost() which takes no arguments and sets the values of the variable totalCost. 1c. Add the following public functions: - Accessor and Mutators for...

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