ok lets see where to even start. I had a an assignment to write an inventory program using structures and functions. It is the code below:
#include <stdio.h> #include <iostream> using namespace std; struct ProductInfo { char pro_name[51]; char pro_desc[51]; char upc[13]; int inventory; }; void addProduct(ProductInfo &); void showProduct(ProductInfo); int main() { ProductInfo pro; int size=0; cout<< "How many products would you like to enter? \n"; cin>>size; if (size == 0)return; for (int i=0; i<size; i++) { cout<< "Enter the data for product " << (i+1) << endl; addProduct(pro); } for (int i=0; i<size;i++) showProduct(pro); return 0; } void addProduct (ProductInfo &pro) { cout<< "Enter product name: \n"; cin.ignore (); cin.getline(pro.pro_name, 51); cout<< "Enter a description for the product: \n"; cin.ignore (); cin.getline(pro.pro_desc, 51); cout << "Enter product UPC: \n"; cin.ignore (); cin.getline(pro.upc, 13); cout << "Enter the amount of products in stock: \n"; cin >> pro.inventory; return; } void showProduct (ProductInfo pro) { // cout<< fixed << showpoint << setprecision(2); cout << "Product Name :" << pro.pro_name << endl; cout << "Product Description :" << pro.pro_desc << endl; cout << "Product UPC :" << pro.upc << endl; cout << "Product in stock :" << pro.inventory << endl; }
Now i need to modify the program to uses classes instead of structures. So my question is , the void functions that i have in the code, would they be placed in the class or outside of it? I am so lost in how to modify this. The new program also has to be menu driven but I have no problems with that.