Question

In: Computer Science

How can I improve my code below to meet the requirements of this assignment with syntax...

How can I improve my code below to meet the requirements of this assignment with syntax add to my code to complete the assignment below:

#include <iostream>
#include <vector>
using namespace std;

class Inventory {
private:
int itemNumber;
int quantity;

double cost;
double totalCost;

public:
Inventory() { itemNumber = 0; quantity = 0; cost = 0; totalCost = 0; }
Inventory(int n, int q, double c) {
itemNumber = n; quantity = q; cost = c; setTotalCost();
}
void setItemNumber(int n) {
itemNumber = n;
}
void setCost(double c) {
cost = c;
}
void setQuantity(int q) {
quantity = q;
}
void setTotalCost() {
totalCost = quantity * cost;
}
int getItemNumber() const {
return itemNumber;
}
int getQuantity() const {
return quantity;
}
double getCost() const {
return cost;
}
double getTotalCost() const {
return totalCost;
}
};


class CashRegister {
private:
Inventory Inv;
int itemNumber;
int quantity;
double cost;
public:
CashRegister(Inventory& temp, int q) {
itemNumber = temp.getItemNumber();
quantity = q; cost = temp.getCost();
temp.setQuantity(temp.getQuantity() - q);
} //constructor
CashRegister() {
itemNumber = 0; quantity = 0; cost = 0; Inv.setItemNumber(0);
Inv.setQuantity(0); Inv.setCost(0);
}
double getUnitPrice() const { return 1.3 * cost; }
double getSubTotal() const { return 1.3 * cost * quantity; } // unitprice * qty
double getTax() const { return 1.3 * cost * quantity * .06; } // subtotal*.06
double getTotal() const { return 1.3 * cost * quantity * 1.06; } // subtotal plus 6% tax   
};


int main()
{
int q;
int n;
int pause;
const int MAX_INV_SIZE = 5;
vector <Inventory> Inv(MAX_INV_SIZE);
Inv[0].setItemNumber(0);
Inv[0].setQuantity(10);
Inv[0].setCost(4.34);
Inv[1].setItemNumber(1);
Inv[1].setQuantity(5);
Inv[1].setCost(9.20);
Inv[2].setItemNumber(2);
Inv[2].setQuantity(100);
Inv[2].setCost(3.00);
Inv[3].setItemNumber(3);
Inv[3].setQuantity(12);
Inv[3].setCost(.5);
Inv[4].setItemNumber(4);
Inv[4].setQuantity(18);
Inv[4].setCost(1);
cout << "Welcome to the Cash register program...." << endl;
cout << "Which item would you like to purchase? " << endl;
cout << "1. Adjustable Wrench" << endl;
cout << "2. Screwdriver" << endl;
cout << "3. Pliers" << endl;
cout << "4. Ratchet" << endl;
cout << "5. Socket Wrench" << endl;
cin >> n;
while (n > 5 || n < 1) { cout << "Invalid entry...try again: "; cin >> n; }
n--;
cout << "Enter the quantity purchased: "; cin >> q;
while (q < 0) { cout << "We don't sell negative # of items...try again: "; cin >> q; }
CashRegister C(Inv[n], q);
cout << "Subtotal: " << C.getSubTotal() << endl;
cout << "Tax: " << C.getTax() << endl;
cout << "Total: " << C.getTotal() << endl;
cout << "Items left: " << Inv[n].getQuantity();
cin >> pause;
}

Cash Register Basic Steps in Creating your Program

1. Plan your logic before working on the project and review the syntax you will use in the project. Think about how you want the lines of output to be displayed to the user. You will want to tell the user what the program does and what type of input you expect from the user (Introduction to the User). Select names of the variables you will use in the program.

2. Create a C++ project in Visual Studio 2012. And have the code window open to write the project code. Display Using Visual Studio to create your program in C++ and follow the instructions on creating the project.  Declare variables to hold information about tank capacity and mpg

 Set up information about this program and what the user will enter and results expected

 Ask the user to enter some information requested and save the response to a variable. Make sure the position for the user to enter information is on the same line as the request for information.

 Use line spacing (endl or \n) to separate lines of output to make it easy for the user to read the information.

3. Documentation: All lines of code must be documented.

 Use the syntax to designate lines in code as comments (//)

 These comments can be at the end of a line of code or in a group definition at the beginning of a section of code. All methods and function need a group heading document.

4. Run the program using Ctrl+F5. Debug the code, making sure all calculations are correct and the line spacing is suitable for readability.

Your program Assignment Design a CashRegister class that can be used with the Inventory Item class discussed in the chapter.

The CashRegister class should perform the following:

1. Ask the user for the item and quantity being purchased.

2. Get the item’s cost from the Inventory Item object.

3. Add a 30% profit to the cost to get the item’s unit price.

4. Multiply the unit price times the quantity being purchased to get the purchase subtotal.

5. Compute the 6% sales tax on the subtotal to get the purchase total.

6. Display the purchase subtotal, tax and total on the screen

7. Subtract the quantity being purchased from the on Hand variable of the Inventory Item class object. Implement both classes in a complete program. Feel free to modify the Inventory Item class in any way necessary. Be sure and loop the program so that multiple items can be purchases Input Validation: Do not accept a negative value for the quantity of items being purchased.

Solutions

Expert Solution

#include <iostream>
#include <vector>
using namespace std;

class Inventory {
private:
int itemNumber;
int quantity;

double cost;
double totalCost;

public:
Inventory() { itemNumber = 0; quantity = 0; cost = 0; totalCost = 0; }
Inventory(int n, int q, double c) {
itemNumber = n; quantity = q; cost = c; setTotalCost();
}
void setItemNumber(int n) {
itemNumber = n;
}
void setCost(double c) {
cost = c;
}
void setQuantity(int q) {
quantity = q;
}
void setTotalCost() {
totalCost = quantity * cost;
}
int getItemNumber() const {
return itemNumber;
}
int getQuantity() const {
return quantity;
}
double getCost() const {
return cost;
}
double getTotalCost() const {
return totalCost;
}
};


class CashRegister {
private:
Inventory Inv;
int itemNumber;
int quantity;
double cost;
public:
CashRegister(Inventory& temp, int q) {
itemNumber = temp.getItemNumber();
quantity = q; cost = temp.getCost();
temp.setQuantity(temp.getQuantity() - q);
} //constructor
CashRegister() {
itemNumber = 0; quantity = 0; cost = 0; Inv.setItemNumber(0);
Inv.setQuantity(0); Inv.setCost(0);
}
double getUnitPrice() const { return 1.3 * cost; }
double getSubTotal() const { return 1.3 * cost * quantity; } // unitprice * qty
double getTax() const { return 1.3 * cost * quantity * .06; } // subtotal*.06
double getTotal() const { return 1.3 * cost * quantity * 1.06; } // subtotal plus 6% tax   
};


int main()
{
int q;
int n;
int pause;
int temp;
const int MAX_INV_SIZE = 5;
//create vector and set values for five items
vector <Inventory> Inv(MAX_INV_SIZE);
Inv[0].setItemNumber(0);
Inv[0].setQuantity(1);
Inv[0].setCost(4.34);
Inv[1].setItemNumber(1);
Inv[1].setQuantity(5);
Inv[1].setCost(9.20);
Inv[2].setItemNumber(2);
Inv[2].setQuantity(100);
Inv[2].setCost(3.00);
Inv[3].setItemNumber(3);
Inv[3].setQuantity(12);
Inv[3].setCost(.5);
Inv[4].setItemNumber(4);
Inv[4].setQuantity(18);
Inv[4].setCost(1);
while(1)//looping for repeat purchase until press 6
{
//Displaying menu items for purchasing//
cout << "\nWelcome to the Cash register program...." << endl;
cout << "1. Adjustable Wrench" << endl;
cout << "2. Screwdriver" << endl;
cout << "3. Pliers" << endl;
cout << "4. Ratchet" << endl;
cout << "5. Socket Wrench" << endl;
cout << "Which item would you like to purchase?(Press 6 for Exit) " ;
cin >> n;
if(n==6) break;
if(n > 6 || n < 1) cout << "Invalid entry...try again: "<< endl;
else
{
n--; //to set index (starting index 0)
if(Inv[n].getQuantity()>0){ //check available quantity empty condition
cout << "Enter the quantity purchased(greater than 0): "; cin >> q;
if(q >0) { //check if user enters negative number
if(Inv[n].getQuantity()<q){ //check if available quantity less than user enters
cout << "Only Avaliable "<<Inv[n].getQuantity()<< endl;
temp=Inv[n].getQuantity();//available quantity purchased
}
else
temp=q;//full quantity available
CashRegister C(Inv[n],temp);//create object of class and set values
//Displaying values in console output
cout << " Subtotal : " << C.getSubTotal() << endl;
cout << " Tax : " << C.getTax() << endl;
cout << " Total : " << C.getTotal() << endl;
cout << " Items left: " << Inv[n].getQuantity();
}
else
cout << "We don't sell negative # of items...try again: "<<endl;
}
else
cout<<"Sorry,stock empty";
}
}
return 0;
}


Related Solutions

The code following is what I have so far. It does not meet my requirements. My...
The code following is what I have so far. It does not meet my requirements. My problem is that while this program runs, it doesn't let the user execute the functions of addBook, isInList or compareLists to add, check, or compare. Please assist in correcting this issue. Thank you! Write a C++ program to implement a singly linked list of books. The book details should include the following: title, author, and ISBN. The program should include the following functions: addBook:...
In Python I have a code: here's my problem, and below it is my code. Below...
In Python I have a code: here's my problem, and below it is my code. Below that is the error I received. Please assist. Complete the swapCaps() function to change all lowercase letters in string to uppercase letters and all uppercase letters to lowercase letters. Anything else remains the same. Examples: swapCaps( 'Hope you are all enjoying October' ) returns 'hOPE YOU ARE ALL ENJOYING oCTOBER' swapCaps( 'i hope my caps lock does not get stuck on' ) returns 'I...
How can i assess my skills and develop a plan to improve the skills to be...
How can i assess my skills and develop a plan to improve the skills to be successful in the financial services industry?
How can I improve my thesis for an essay for higher education as I only scored...
How can I improve my thesis for an essay for higher education as I only scored 20/40 in this assignment They say I Say thesis Although Henry Bienen has some compelling reasons regarding pursuing higher education in debate “is college for everyone” but we should study the current job market before we consider higher education. While many technical jobs require hands-on experience with interview skills but higher education might not include proper curriculum to handle such necessities for job security...
Below is my source code for file merging. when i run the code my merged file...
Below is my source code for file merging. when i run the code my merged file is blank and it never shows merging complete prompt. i dont see any errors or why my code would be causing this. i saved both files with male names and female names in the same location my source code is in as a rtf #include #include #include using namespace std; int main() { ifstream inFile1; ifstream inFile2; ofstream outFile1; int mClientNumber, fClientNumber; string mClientName;...
How do I add the information below to my current code that I have also posted...
How do I add the information below to my current code that I have also posted below. <!DOCTYPE html> <html> <!-- The author of this code is: Ikeem Mays --> <body> <header> <h1> My Grocery Site </h1> </header> <article> This is web content about a grocery store that might be in any town. The store stocks fresh produce, as well as essential grocery items. Below are category lists of products you can find in the grocery store. </article> <div class...
Python I want to name my hero and my alien in my code how do I...
Python I want to name my hero and my alien in my code how do I do that: Keep in mind I don't want to change my code except to give the hero and alien a name import random class Hero:     def __init__(self,ammo,health):         self.ammo=ammo         self.health=health     def blast(self):         print("The Hero blasts an Alien!")         if self.ammo>0:             self.ammo-=1             return True         else:             print("Oh no! Hero is out of ammo.")             return False     def...
I have the following code for my java class assignment but i am having an issue...
I have the following code for my java class assignment but i am having an issue with this error i keep getting. On the following lines: return new Circle(color, radius); return new Rectangle(color, length, width); I am getting the following error for each line: "non-static variable this cannot be referenced from a static context" Here is the code I have: /* * ShapeDemo - simple inheritance hierarchy and dynamic binding. * * The Shape class must be compiled before the...
1.how can i improve my memory? 2. how is memory measured? 3. how does the brain...
1.how can i improve my memory? 2. how is memory measured? 3. how does the brain form and store memorise?
Below is my code in C#, When I run it, the output shows System.32[], Can you...
Below is my code in C#, When I run it, the output shows System.32[], Can you please check and let me know what is the problem in the code. class Program { static void Main(string[] args) { int number=12; Console.WriteLine(FizzArray(number)); } public static int[] FizzArray(int number) { int[] array = new int[number]; for (int i = 1; i < number; i++) array[i] = i; return array; }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT