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

In summary: Num2; cout << "Enter product's wholesale cost: " << endl; cin >> whsleCost; cout << "Enter product's retail cost: " << endl; //cin >> retCost; cout << "The total cost of the shipment will be: " << endl; //cout << whsleCost + retCost; Customer c;c.SetCustomerName("John");c.SetCustomerID(123456);products p;p.SetProductName("Desk");p.SetModelNumber(1234
  • #1
carl123
56
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:
Technology news on Phys.org
  • #2
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;
}
 

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

What is the difference between private and public data in a C++ Online Store Program?

The main difference between private and public data in a C++ Online Store Program is the level of access that other parts of the program have to that data. Private data can only be accessed and modified by the class that it belongs to, while public data can be accessed and modified by any part of the program. This means that private data is more secure and protected from outside interference, while public data is more easily accessible.

Why is it important to use private data in a C++ Online Store Program?

Using private data in a C++ Online Store Program is important for maintaining data integrity and security. By restricting access to certain data, we can ensure that it is not accidentally or maliciously modified by other parts of the program. This also helps to prevent errors and bugs that can arise from unexpected data modifications.

When should I use public data in a C++ Online Store Program?

Public data in a C++ Online Store Program should be used when we want that data to be accessible and modifiable by different parts of the program. For example, if we want to display a product's price on the website, we would use public data so that the website can access and display that information. However, if we want to store sensitive information like customer's credit card details, we would use private data to ensure its security.

Can private data be accessed by other classes in a C++ Online Store Program?

No, private data cannot be accessed by other classes in a C++ Online Store Program. Private data is only accessible within the class that it belongs to. This helps to maintain encapsulation and prevent other classes from modifying or interfering with the data. If we want to allow other classes to access private data, we can use getter and setter methods to control the access.

How does using private and public data affect the overall efficiency of a C++ Online Store Program?

Using private and public data in a C++ Online Store Program can improve its efficiency by reducing the chances of errors and unexpected data modifications. By restricting access to certain data, we can also prevent unnecessary data processing and improve the overall performance of the program. However, using public data can also make the program more vulnerable to external interference, so it is important to carefully consider which data should be made public.

Similar threads

Replies
6
Views
1K
Replies
1
Views
1K
Replies
4
Views
4K
Replies
21
Views
9K
Replies
1
Views
2K
Back
Top