Question

Contents? Introduction Existing code & UML UML Code Changes to be made to the program tester_with_mods.cpp...

Contents?
Introduction
Existing code & UML
UML
Code
Changes to be made to the program
tester_with_mods.cpp
Submit Instructions?


Introduction
The purpose of this assignment is to provide you with experience in working with objects in C++.
Existing code & UML
You have been provided with a class that describes the products maintained in a company’s inventory. The class maintains the following attributes:

Name of attribute
Data Type
productId
string
productPrice
float

Accessor and Mutator methods have been created for these attributes. Additionally, the class also contains a default constructor and a print function.
UML
The UML diagram for this class is as follows:


Code
The class’s .h, .cpp and the code that tests the class can be downloaded from clicking on this link or from BlackBoard. Code is shown below:

product.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <string>
using namespace std;

class product
{
private:
string productId;
float productPrice;
public:
product(void);
void setProductId(string);
void setProductPrice(float);

string getProductId();
float getProductPrice();

void print();
};

product.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "product.h"

product::product(void)
{
productId = "--";
productPrice = 0.99f;
}

void product::setProductId(string _productId)
{
productId = _productId;
}

void product::setProductPrice(float _productPrice)
{
productPrice = _productPrice;
}
string product::getProductId()
{
return productId;
}

float product::getProductPrice()
{
return productPrice;
}

void product::print()
{
cout << setprecision(2) << fixed;
cout << "id=" << productId << ", Price= " << productPrice << endl;
}

tester_original.cpp

1
2
3
4
5
6
7
8
9
10
#include <iostream>
using namespace std;
# include "product.h"

int main()
{
product product01;
product01.print();
return 0;
}

Output produced by this code is shown below:

Id = --, Price = $0.99
Press any key to continue . . .   

Changes to be made to the program
In order to complete the in-class assignment, you need to make the following changes to the object.
#
Change

1
Place validation code in the mutator method for product price to ensure that no negative numbers are placed in price
15
2
Add a string attribute to the object called aisleId.
Initialize it to “-none-“ in the constructor.
Create accessor and mutator methods for it. No validation code needs to be placed in the mutator function.
Print it out in the print function

20
3
Create a class function called increasePriceBy15Percent.
It should increase product price by 15%

15



The UML diagram of the completed assignment is as follows. New attributes and functions are highlighted. Functions circled in maroon need to be modified.




tester_with_mods.cpp
Download the new class tester program by clicking link , or from BB. Use it to test the product class after changes have been made to it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
using namespace std;
# include "product.h"

int main()
{
product product01;

//------- object after instantiation ---------
cout << "---product01 after instantiation ---\n";
product01.print();

//--------- test setProductPrice --------
product01.setProductPrice(123.45);
cout << "\n---product01 after product01.setProductPrice(123.45) ---\n";
product01.print();

//--------- test negative setProductPrice --------
product01.setProductPrice(-51);
cout << "\n---product01 after product01.setProductPrice(-51) ---\n";
product01.print();

//-------- test setAisleId ----
product01.setAisleId("A12");
cout << "\n---product01 after product01.setAisleId(\"A12\") ---\n";
product01.print();

//-------- test increasePriceBy15Percent() -------
product01.increasePriceBy15Percent();
cout << "\n---product01 after product01.increasePriceBy15Percent() ---\n";
product01.print();
}

Sample output from my completed program is as follows:

---product01 after instantiation ---
id=--, Price= 0.99, Aisle Id = --none--

---product01 after product01.setProductPrice(123.45) ---
id=--, Price= 123.45, Aisle Id = --none--
-- Invalid product price --

---product01 after product01.setProductPrice(-51) ---
id=--, Price= 123.45, Aisle Id = --none--

---product01 after product01.setAisleId("A12") ---
id=--, Price= 123.45, Aisle Id = A12

---product01 after product01.increasePriceBy15Percent() ---
id=--, Price= 141.97, Aisle Id = A12

Submit Instructions
Submit one of the following via BlackBoard's submission tool.
Zipped solution folder created by Visual Studio
The following files
product.h
product.cpp
tester_with_mods.cpp



---product01 after instantiation ---
id=--, Price= 0.99, Aisle Id = --none--

---product01 after product01.setProductPrice(123.45) ---
id=--, Price= 123.45, Aisle Id = --none--
-- Invalid product price --

---product01 after product01.setProductPrice(-51) ---
id=--, Price= 123.45, Aisle Id = --none--

---product01 after product01.setAisleId("A12") ---
id=--, Price= 123.45, Aisle Id = A12

---product01 after product01.increasePriceBy15Percent() ---
id=--, Price= 141.97, Aisle Id = A12

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

//Definition for updated file product.h can be written as

#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <string>
using namespace std;

class product
{
private:
string productId;
string aisleId; //Definition for aisleId
float productPrice;
public:
product(void);
void setProductId(string);
void setProductPrice(float);
void setAisleId(string); //Definition for mutator function

string getProductId();
float getProductPrice();
string getAisleId(); //Definition for accessor function

void print();
void increasePriceby15Percent(); //Definition for increase price by 15 percent
};

//Definition for the updated file product.cpp can be written as

#include "product.h"

product::product(void)

{

productId = "--";

productPrice = 0.99f;

strcpy(aisleId,"-none-"); //Initializing the value of aisleId

}

void product::setProductId(string _productId)

{

productId = _productId;

}

void product::setProductPrice(float _productPrice)

{

if(_productPrice>=0.0) //Validate for non-negative values

produtcPrice = _productPrice;

else

cout<<"\nWrong input";

}

//Mutator method for aisleId

void product::setAisleId(string _aisleId)

{

strcpy(aisleId, _aisleId);

}

string product::getProductId()

{

return productId;

}

float product::getProductPrice()

{

return productPrice;

}

//Accessor function for aisleId

string product::getAisleId()

{

return aisleId;

}

void product::print()

{

cout << setprecision(2) << fixed;

cout << "id=" << productId << ", Price= " << productPrice << endl;

}

//function to increase price by 15 percent

void increasePriceBy15Percent()

{

productPrice = productPrice+(productPrice*0.15);

}

Add a comment
Know the answer?
Add Answer to:
Contents? Introduction Existing code & UML UML Code Changes to be made to the program tester_with_mods.cpp...
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
  • Edit this C++ code to show the output as well. #include<iostream> #include<cstring> using namespace std; class...

    Edit this C++ code to show the output as well. #include<iostream> #include<cstring> using namespace std; class Product { private:    // private variables    int id_number;    char pDescription[40];    int mId;    double productPrice;    double productMarkUp;    int qty; public:    // constructor    Product() {        id_number = 0;        strcpy_s(pDescription, "");        mId = 0;        productPrice = 0.0;        productMarkUp = 0.0;        qty = 0;    }   ...

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

  • The following C++ code include 3 files: Patient.h, Patient.cpp and Main.cpp. The program basically creates and stores patient records. The original code has everything in a single .cpp file. I tried t...

    The following C++ code include 3 files: Patient.h, Patient.cpp and Main.cpp. The program basically creates and stores patient records. The original code has everything in a single .cpp file. I tried to divide the code in 3 parts (Patient.h, Patient.cpp and Main.cpp), but it is giving me errors. Patient.h #ifndef PATIENT_H #define PATIENT_H #include <string> #include "Patient.cpp" using namespace std; class Patient{ private : string firstname; string lastname; string location; static int cnt; int id; public : Patient(string, string, string);...

  •       C++ -- Vector of Bank Accounts (15 pts) Please help! :( Use csegrid or Clion for...

          C++ -- Vector of Bank Accounts (15 pts) Please help! :( Use csegrid or Clion for this part Add on to the lab12a solution(THIS IS PROVIDED BELOW). You will add an overload operator function to the operator << and a sort function (in functions.h and functions.cpp)    Print out the customer’s name, address, account number and balance using whatever formatting you would like    Sort on account balance (hint: you can overload the < operator and use sort from the...

  • Greetings, everybody I already started working in this program. I just need someone to help me...

    Greetings, everybody I already started working in this program. I just need someone to help me complete this part of the assignment (my program has 4 parts of code: main.cpp; Student.cpp; Student.h; StudentGrades.cpp; StudentGrades.h) Just Modify only the StudentGrades.h and StudentGrades.cpp files to correct all defect you will need to provide implementation for the copy constructor, assignment operator, and destructor for the StudentGrades class. Here are my files: (1) Main.cpp #include <iostream> #include <string> #include "StudentGrades.h" using namespace std; int...

  • C++ #include <iostream> using namespace std; bool checkinventoryid(int id) {    return id > 0; }...

    C++ #include <iostream> using namespace std; bool checkinventoryid(int id) {    return id > 0; } bool checkinventoryprice(float price) {    return price > 0; } void endProgram() {    system("pause");    exit(0); } void errorID(string str) {    cout << "Invalid Id!!! " << str << " should be greater than 0" << endl; } void errorPrice(string str) {    cout << "Invalid Price!!!" << str << " should be greater than 0" << endl; } int inputId() {...

  • Please provide a multi lined pseudo code for the program below.....also it is giving me a...

    Please provide a multi lined pseudo code for the program below.....also it is giving me a build error? Could you possibly tell me how to fix the error too? #include <iostream> #include <string> using namespace std; class ship { public: string name; int year; ship(string n, int y) { name = n; year = y; } int getYear() { return year; } string getName() { return name; } void setYear(int y) { year = y; } void setName(string n) {...

  • Here is the code from the previous three steps: #include <iostream> using namespace std; class Student...

    Here is the code from the previous three steps: #include <iostream> using namespace std; class Student { private: //class variables int ID; string firstName,lastName; public: Student(int ID,string firstName,string lastName) //constructor { this->ID=ID; this->firstName=firstName; this->lastName=lastName; } int getID() //getter method { return ID; } virtual string getType() = 0; //pure virtual function virtual void printInfo() //virtual function to print basic details of a student { cout << "Student type: " << getType() << endl; cout << "Student ID: " << ID...

  • Hello, I have written a code that I now need to make changes so that arrays...

    Hello, I have written a code that I now need to make changes so that arrays are transferred to the functions as pointer variable. Below is my code I already have. #include<iostream> #include<string> #include<iomanip> using namespace std; //functions prototypes void getData(string id[], int correct[], int NUM_STUDENT); void calculate(int correct[], int incorrect[], int score[], int NUM_STUDENT); double average(int score[], int NUM_STUDENT); void Display(string id[], int correct[], int incorrect[], int score[], double average, int NUM_STUDENT); int findHigh(string id[], int score[], int NUM_STUDENT);...

  • Hey, so i am trying to have my program read a text file using a structure...

    Hey, so i am trying to have my program read a text file using a structure but i also want to be able to modify the results(I kinda have this part but it could be better). I cant seem to get it to read the file(all the values come up as 0 and i'm not sure why because in my other program where it wrote to the txt file the values are on the txt file) i copied and pasted...

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