C++ Shopping Cart

Hi guys! im having a hard time completing my program. im stuck with adding products only please help me thanks alot!

here are the components:
- Classes and Data Abstraction Usage
- File Handling

and the Requirements
1. Product information must be saved in a text file named Products.txt. This text file should have two columns to store the Product information. Required columns are ProductName and ProductPrice

Sample data inside Products.txt

2. Another text file Sales.txt is needed to handle the sales of the product. This is to track all of the purchases made in all products. Required columns are ProductName, ProductPrice, Quantity

Sample data inside Sales.txt


3. Sooooo the calculation of sales per product is shown below:


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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include<iostream>
#include<fstream>
#include<string>
#include <sstream>

using namespace std;

void AddProduct();
void EditProductPrice();
void PurchaseProduct();
void ViewSalesPerProduct();


void main()
{
	int Choice;

	cout<<"Main Option";
	cout<<"\n1 Add Product";
	cout<<"\n2 Edit Product Price";
	cout<<"\n3 Purchase Product";
	cout<<"\n4 View Sales Per Product";
	cout<<"\n5 Exit";
	cout<<"\n\nChoice: ";
	cin>>Choice;
	switch(Choice)
	{
		case 1: 
			AddProduct();
			break;
		case 2:
			EditProductPrice();
			break;
		case 3:
			PurchaseProduct();
			break;
		case 4:
			ViewSalesPerProduct();
			break;
		case 5:
			exit(0);
			break;
		default:
			cout<<"Invalid choice!";
			break;
	}
}

void AddProduct()
{
	ofstream oStream;// writes in the text (Registration)
	

	string myProduct;
	string myPrice;


	int price;
	cout<<"Enter Product To Add: ";
	cin>>myProduct;
	cout<<"\nPrice: ";
	cin>>price;

	ostringstream convert;   // used to convert the int -> string
	convert << price;      
	myPrice = convert.str();

	cout<< "Product "+ myProduct + "(" + myPrice + " pesos) has been added to Products.txt";
	oStream.open("Products.txt");
	oStream << myProduct +" "+ myPrice +"\n";
	oStream.close();



	main();

}
void EditProductPrice()
{
	
}
void PurchaseProduct()
{

}
void ViewSalesPerProduct()
{

}
Thou shall not call main() from within your program.

Study while-loop for repeating the menu.
Sorry keskiverto, yes i will study while-loop but my main problem is how can i code for editProductprice, PurchaseProduct and ViewSalesProduct. thank you :)
Your AddProduct reads user input and writes to a file. If you want to continue that path:
ViewSalesPerProduct reads file(s) and prints values.
PurchaseProduct reads file(s), reads user input, and writes file.
EditProductPrice reads file, reads user input, and writes file.

Sounds a bit inconvenient.
- Classes and Data Abstraction Usage

I see no use of classes in your code.

How about this:
1. Program starts by reading files into memory. (Use std::vector of class objects.)
2. User selects operations that modify the in memory copy.
3. Program updates files at the very end, after the user has chosen to quit.
thank you keskiverto but our professor told us to make use of Classes and Data Abstraction.
our professor told us to make use of

And so did I too. (Without even knowing what "Classes and Data Abstraction" means in your school.)
Make a class or two.
Topic archived. No new replies allowed.