Well I've spent a few sleepless nights (VERY RECENTLY -.o) I wanted to get people's opinion at my first semi-serious program ever. (First thing i made after doing a few tutorials and a lot of mountain dew.
Thats the class with the two functions that I got working. Enough fiddeling gets anything working lolCode://This is the Customer.h file.... #include <iostream> /* This is another way to make comments */ #include <iomanip> /* These are the headers we need, so remember to */ #include <fstream> /* include them all in the calss. You will learn */ #include <sstream> /* past where I have gotten with these tutorials */ #include <string> using namespace std; class Customer //Class for the C++ Tutorial Register { private: //Notice these are colons! public: Customer(); ~Customer(); char Customer::GetData(int id); int Customer::GetLines(char *file); }search; Customer::Customer() //Constructor for the C++ Class { }; Customer::~Customer() //destructor for the C++ Tutorial { }; char Customer::GetData(int id) //This is a function to get and read whatever is { //in the corollating ID#.txt file. ostringstream File_ID; File_ID<<id<<".txt"; string line; ifstream Cust_File (File_ID.str().c_str()); if (Cust_File.is_open()) { while (! Cust_File.eof() ) { getline (Cust_File,line); cout << line << endl; } Cust_File.close(); } else cout << "Unable to open file"<<File_ID; cin.get(); return 0; }; int Customer::GetLines(char * file) //This will get the number of items in { //the "Items.txt" file which makes using int y = 0; //loops through the program easier. string line; ifstream productlist(file); if(productlist.is_open()) while (! productlist.eof() ) { getline (productlist,line); y++; } productlist.close(); return y; };
Shhhhhh It is a SECRETIVE program not really, i am just beyond happy that i got it working. Offer some critisism on what i could do to make it better!Code://////////////////////////////////////////////////////////////////////////////// /////////This was created by Rum//////////////////////CRAZY//////// /////////////////////////////////////2007, Januaru/////////////////////// #include <iostream> /* This is another way to make comments */ #include <iomanip> /* These are the headers we need, so remember to */ #include <fstream> /* use them all wisely. Hopefully you will learn */ #include <sstream> /* past where i have gotten with these tutorials */ #include <string> /* You are our programming legacy, feel honoured.*/ #include <time.h> #include "Customer.h" using namespace std; //Let's Start! //This will allow me to use my GetLines Function. int main() { string zipstr; /* I like to categorize all my variables once I'm */ string string; /*Done writing the code. So don't worry about your */ /*Messy code when you first start writing the code */ char dateStr [9]; /*All you should care about in the beginning is */ char timeStr [9]; /*Getting the program to work, worry about anything*/ char zip[50]; /*Else after that. */ char address[70]; char name[50]; char phone[20]; char description[200]; int x=0; int correct = 2; int id=1000; int id2; int option; int Max_Items; double total_trnsctn = 0; double cash_tend=0.00; double change=0.00; double totaly=0.00; double x2=0; Customer search; Max_Items = search.GetLines("Items.txt."); //Get the number of lines in the Items.txt file. struct Product{ /*Now this is where we use a structure*/ std::string name; double price; int quant; }; struct Product item[90]={ }; //which are useful in keeping variables //logically stored and easily reachable fstream p_file("Items.txt"); //Declares p_file as a buffer to "Items.txt" x=0; while(x<Max_Items)//Gets the names of all the items in the "Items.txt" file. { getline(p_file,item[x].name,'\n'); x++; } p_file.close(); x=0; fstream i_file("Prices.txt"); while(x<Max_Items)//Gets the prices of all the items in the "Prices.txt" file. { i_file>>item[x].price; x++; } x=0; i_file.close(); //This is where the users opens up and will first see. for (int i=0;i<100;i++) { cout<<"\n"; cout<<"_____________________________________________________\n"; cout<<"| w w |\n"; cout<<"| w w |\n"; cout<<"| w w w |\n"; cout<<"| w w w w eee L cccc o o m m eee |\n"; cout<<"| w w w w ee L c o o m m m m ee |\n"; cout<<"| w w eee LLL cccc o o m m m eee |\n"; cout<<"| |\n"; cout<<"|___________________________________________________|\n"; cout<<"_____________________________________________________\n"; cout<<"| ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! |\n"; cout<<"|! ! ! ! ! ! ! ! ! Adam's Super Store! ! ! ! ! ! ! !|\n"; cout<<"| ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! |\n"; cout<<"|! !Providing the Southeastern Region of Vermont ! !|\n"; cout<<"| ! ! ! ! ! !with all of its computer needs ! ! ! ! |\n"; cout<<"|! ! ! ! ! ! ! !for 18 wonderful years ! ! ! ! ! ! !|\n"; cout<<"| ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! |\n"; cout<<"|!_!_!_!_!_!_!_!_!_!_!_!_!_!_!_!_!_!_!_!_!_!_!_!_!_!|\n"; cout<<"-----------------------------------------------------\n"; cout<<"\n"; cout<<"Please chose an option:\n"; cout<<"(1)New Customer\n(2)Previos Customer\n(3)Exit\n"; cin>>option; system("cls"); //doesn't compound. id++; switch(option) { case 1: while(correct==2) //This loop will get the custome's info. { //Adds one to the int id. cin.ignore(); cout<<"Please enter name:\n"; cin.getline(name, 50, '\n'); cout<<"Please enter address:\n"; cin.getline(address, 70, '\n'); cout<<"Please enter zip code:\n"; getline(cin, zipstr); cout<<"Please enter phone number:\n"; cin.getline(phone, 20, '\n'); cout<<"Please enter description:\n"; cin.getline(description, 200, '\n'); system("cls"); cout<<endl<<"Customer ID # "<<id<<endl; cout<<"Name: "<<name<<endl; cout<<"Address: "<<address<<endl; cout<<"Zip Code: "<<zipstr<<endl; cout<<"Phone: "<<phone<<endl; cout<<"Description: "<<description<<endl; cout<<"\nIs this information correct?\n(1)Yes\n(2)No\n"; cin>>correct; system("cls"); } break; case 2: correct=2; while(correct==2) { cout<<"Please enter the Customer's ID#: "<<endl; cin>>id2; system("cls"); cout<<"\n\n\n\n"; cout<<"_____________________________________________________\n"; cout<<"| w w |\n"; cout<<"| w w |\n"; cout<<"| w w w |\n"; cout<<"| w w w w eee L cccc o o m m eee |\n"; cout<<"| w w w w ee L c o o m m m m ee |\n"; cout<<"| w w eee LLL cccc o o m m m eee |\n"; cout<<"| |\n"; cout<<"|___________________________________________________|\n"; cout<<"\n\n\n\n"; search.Customer::GetData(id2); cout<<"\nIs this information correct?\n(1)Yes\n(2)No\n"; cin>>correct; } break; case 3: return 0; break; default: cout<<"Your entered an Invalid choice\n"; break; } correct=2; while(correct!=1) { while(x<Max_Items) { cout<<"How many "<<item[x].name<<" were purchased :\n\n"; cin>>item[x].quant; x++; } system("cls"); x=0; while(x<Max_Items) { cout<<"Customer Prushased "<<item[x].quant<<" "<<item[x].name<<" at $"<<item[x].price<<" each"<<endl<<endl; x++; } x=0; cout<<"\n\nIs this Correct?\n(1)Yes\n(2)No\n\n"; cin>>correct; system("cls"); } while(x<Max_Items)//Fills the structure's object's total price. { total_trnsctn = total_trnsctn + (item[x].quant * item[x].price) ; x++; } x = 0; cout<<"\nTotal Cost: "<<total_trnsctn<<endl; cout<<"Cash Tended: \n"; cin>>cash_tend; change=cash_tend-total_trnsctn; cout<<"Change: "<<change<<endl<<endl; _strdate( dateStr); cout<<"The current date is "<<dateStr<<endl; _strtime( timeStr ); cout<<"The current time is "<<timeStr<<endl; if(id2!= 0) { id=id2; } ostringstream ID; //By redeclaring my ostringstream each loop ID<<id<<".txt"; //it will act like flushing it. So the string if(id2 != 0) { ofstream a_file(ID.str().c_str()); a_file<<"Customer ID# : "<<id<<endl; a_file.flush(); a_file<<"Customer Name : "<<name<<endl; a_file.flush(); a_file<<"Customer Address : "<<address<<endl; a_file.flush(); a_file<<"Customer Zipcode : "<<zip<<endl; a_file.flush(); a_file<<"Customer Phone : "<<phone<<endl; a_file.flush(); a_file<<"Customer Desc. : "<<description<<endl<<endl; a_file.flush(); a_file<<"Customer Orders : "<<endl<<endl; a_file.flush(); while(x<Max_Items) { a_file<<"Customer Purchased : "<<item[x].quant<<" "<<item[x].name<<" at $"<<item[x].price<<" each\n"; a_file.flush(); x++; } x=0; a_file<<"Total: "<<total_trnsctn<<endl; a_file.flush(); a_file<<"Cash Tended: "<<cash_tend<<endl; a_file.flush(); a_file<<"Change: "<<change<<endl<<endl<<endl; a_file.flush(); a_file<<"Transaction took place on "<<dateStr<<endl; a_file.flush(); a_file<<"at "<<timeStr<<endl<<endl; a_file.flush(); a_file.close(); } else { ofstream a_file( ID.str().c_str(), ios::app); a_file<<"Customer Orders : "<<endl<<endl; a_file.flush(); while(x<Max_Items) { a_file<<"Customer Purchased : "<<item[x].quant<<" "<<item[x].name<<" at $"<<item[x].price<<" each\n"; a_file.flush(); x++; } x=0; a_file<<"Total: "<<total_trnsctn<<endl; a_file.flush(); a_file<<"Cash Tended: "<<cash_tend<<endl; a_file.flush(); a_file<<"Change: "<<change<<endl<<endl<<endl; a_file.flush(); a_file<<"Transaction took place on "<<dateStr<<endl; a_file.flush(); a_file<<"at "<<timeStr<<endl<<endl<<endl; a_file.flush(); a_file.close(); } correct=2; ifstream c_file("CustomerDataBase.txt"); } return 0; }