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

  • Thread starter Thread starter carl123
  • Start date Start date
  • Tags Tags
    C++ Data Program
AI Thread Summary
The discussion revolves around creating a C++ program for an online store that includes functionalities like tracking products, customers, and inventory management. Key features required by the customer include the ability to identify products for sale, manage customer information, process shipments, facilitate purchases, and handle payments. The program should also allow users to retrieve customer and product details.The developer has chosen to implement the program using classes, specifically defining classes for Shipment, Products, and Customer. There is a focus on determining which class attributes should be public or private, indicating a need for guidance on encapsulation in C++. The code provided demonstrates the initial setup of these classes and includes methods for setting and getting various attributes related to shipments, products, and customers.Despite the code running, the developer expresses uncertainty about its functionality and seeks advice on enhancing the program to meet the specified requirements effectively.
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:
Technology 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;
}
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top