C++ Online Store Program (Private vs Public data)

  • Context: C/C++ 
  • Thread starter Thread starter carl123
  • Start date Start date
  • Tags Tags
    C++ Data Program
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 3K views
carl123
Messages
55
Reaction score
0
Write a C++ program based on the following scenario:

You customer wants you to design and then build an online store:

Abilities the customer wants in the system:

Track products and related information.

Track customers, especially what the customer owes

Identify a product that will be for sale. You should read in the name, model number, wholesale cost, and retail cost for the product.

Enter a new customer. You should read in the customer name and ID.

Take a shipment of new products. Read in the model number and quantity. If you don't know what the product is that you're getting, reject the shipment, otherwise add that to inventory.

Let a customer buy something. The customer ID, product model number, and quantity should be taken as input.

If there is sufficient quantity of the product on hand, then the customer should be charged that amount and the product be deducted from inventory.

If there is not sufficient quantity, the sale should be rejected.

Let a customer make a payment. Read in the customer ID and the amount of payment. It's OK for customers to have a positive balance, but they cannot make negative payments.

Find out about a customer: enter a customer ID number, and print out the customer's name, current balance, and a list of what the customer has previously purchased.

Find out about a product: enter a model number and get the name of the product, the amount that has already been sold, and the amount in inventory.

My thoughts so far:

I opted to write the code by using classes.
My proposed classes are customerInfo, productInfo, newShipment, and purchases

I'm confused on what information to make public or private in these classes
 
Last edited:
Physics news on Phys.org
C++ Online Store Program

I'm trying to create an online store program that is supposed to do this:

1. Identify a product that will be for sale. You should read in the name, model number, wholesale cost, and retail cost for the product.
2. Enter a new customer. You should read in the customer name and ID.
3. Take a shipment of new products. Read in the model number and quantity. If you don't know what the product is that you're getting, reject the shipment, otherwise add that to inventory.
4. Let a customer buy something. The customer ID, product model number, and quantity should be taken as input.
- If there is sufficient quantity of the product on hand, then the customer should be charged that amount and the product be deducted from inventory.
- If there is not sufficient quantity, the sale should be rejected.
5. Let a customer make a payment. Read in the customer ID and the amount of payment. It's OK for customers to have a positive balance, but they cannot make negative payments.
6. Find out about a customer: enter a customer ID number, and print out the customer's name, current balance, and a list of what the customer has previously purchased.
7. Find out about a product: enter a model number and get the name of the product, the amount that has already been sold, and the amount in inventory.
8. Print lists of all information about all customers and all products.

I already made 3 classes and declared the private and member variables. My code runs but its running as required by the instructed. I'm also new to C++ so any form of help or guidance will be appreciated. Thanks

Code:
#include <iostream>
#include <string>
#include <vector>

using namespace std;

class Shipment {
public:
	void SetModelNumber(int modelN);
	void SetQuantity(int itemQ);

	int GetModelNumber();
	int GetQuantity();
	//Shipment(); // default constructor

private:
	int modelNum1;
	int itemQty;

};

class Products {
public:
	void SetProductName(string prodN);
	void SetModelNumber(int modelN);
	void SetWholeSaleCost(double wholeSaleC);
	void SetRetailCost(double retC);	string GetProductName();
	int GetModelNumber();
	double GetWholeSaleCost();
	double GetRetailCost();
	//Products(); // default constructorprivate:
	string prodName;
	int modelNum2;
	double whsleCost;
	double retCost;
};

class Customer {
public:
	void SetCustomerName(string custN);
	void SetCustomerID(int custID);
	//void SetCustomerPmt(double custPmt);

	string GetCustomerName();
	int GetCustomerID();
	//Customer(); //default constructor

private:
	string custName;
	int custId;
};

void Shipment::SetModelNumber(int modelN) {
	//cout << "Enter model number for your new shipment: " << endl;
	//cin >> modelNum;
	modelNum1 = modelN;
}

void Shipment::SetQuantity(int itemQ) {
	//cout << "Enter quantitiy for your new shipment: " << endl;
	//cin >> itemQty;
	itemQty = itemQ;
}

void Products::SetProductName(string prodN) {
	//cout << "Enter name of product: " << endl;
	//cin >> prodName;
	prodName = prodN;
}

void Products::SetModelNumber(int modelN) {
	//cout << "Enter model number of product: " << endl;
	//cin >> modelNum;
	modelNum2 = modelN;
}

void Products::SetWholeSaleCost(double wholeSaleC) {
	//cout << "Enter wholesale cost of product: " << endl;
	//cin >> whsleCost;
	whsleCost = wholeSaleC;
}

void Products::SetRetailCost(double retC) {
	//cout << "Enter retail cost for your product: " << endl;
	//cin >> retCost;
	retCost = retC;
}void Customer::SetCustomerName(string custN) {
	//cout << "Enter name of customer" << endl;
	//cin >> custName;
	custName = custN;
}

void Customer::SetCustomerID(int custID) {
	//cout << "Enter customer ID number: " << endl;
	//cin >> custId;
	custId = custID;
}

int Customer::GetCustomerID() {
	return custId;
}

int Products::GetModelNumber() {
	return modelNum2;
}

int Shipment::GetQuantity() {
	return itemQty;
}

int Shipment::GetModelNumber() {
	return modelNum1;

}

string Products::GetProductName() {
	return prodName;
}

double Products::GetWholeSaleCost() {
	return whsleCost;
}

double Products::GetRetailCost() {
	return retCost;
}

string Customer::GetCustomerName() {
	return custName;
}int main() {
	int modelNum1, itemQty, modelNum2, custId;
	double whsleCost, retCost;
	string prodName, custName;

	cout << "Enter shipment's model number: " << endl;
	cin >> modelNum1;
	cout << "Enter shipment's quantity: " << endl;
	cin >> itemQty;
	cout << "Enter product's name: " << endl;
	cin >> prodName;
	cout << "Enter product's model number: " << endl;
	cin >> modelNum2;
	if (modelNum2 != modelNum1){
		cout << "Sorry, item requested does not exist in store" << endl;
		return 0;
	}
	cout << "Enter product's wholesale cost: " << endl;
	cin >> whsleCost;
	cout << "Enter product's retail cost: " << endl;
	cin >> retCost;
	cout << "Enter customer name: " << endl;
	cin >> custName;
	cout << "Enter customer ID: " << endl;
	cin >> custId;
	
	
	Shipment shipInfo1;
	Shipment shipInfo2;
	shipInfo1.SetModelNumber(modelNum1);
	shipInfo2.SetQuantity(itemQty);

	Products prodInfo1;
	Products prodInfo2;
	Products prodInfo3;
	Products prodInfo4;
	prodInfo1.SetProductName(prodName);
	prodInfo2.SetModelNumber(modelNum2);
	prodInfo3.SetWholeSaleCost(whsleCost);
	prodInfo4.SetRetailCost(retCost);	Customer custInfo1;
	Customer custInfo2;
	custInfo1.SetCustomerName(custName);
	custInfo2.SetCustomerID(custId);

	system("pause");

	return 0;
}