Thread: need help with menu program and header files

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    5

    need help with menu program and header files

    Hi there folks,

    This is my very first time here, and I hope that everyone is cool around here.

    Anyho, I'm here looking for some assistance. I created a menu program, and I need help on incorporating header files and two additional C++ files onto my menu program. If anyone here know anything about menu program and header files, and willing to help me out here, just email me to this address:

    [email protected]


    I decided not to post the entire codes in this message board just yet.

    And does this site offers some sort of private messaging??

    thanks,
    D

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    You're gonna want to incorperate it all into a project and compile that. As for headers, do you know how to #include your own headers in a program?
    Sent from my iPadŽ

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    14
    wouldnt you just use #include <iostream> or somthing else?

  4. #4
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    For headers, you would do something similar, but .cpp files, no.
    Sent from my iPadŽ

  5. #5
    Registered User
    Join Date
    Dec 2005
    Posts
    14
    o ok

  6. #6
    Registered User
    Join Date
    Dec 2005
    Posts
    5
    SlyMaelstrom, do you want to help me out via email? I want to send you some attachment that I'd worked on so far.............. then I could explain what I want to do with my program.

  7. #7
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Click on my name and send me a private message. I'd rather not do it by email. Also, you can feel free to post your .cpp files as an attachment. Infact, I'd encourage that as there are many other people on this forum that can help you better than I can.
    Sent from my iPadŽ

  8. #8
    Registered User
    Join Date
    Dec 2005
    Posts
    5
    Quote Originally Posted by SlyMaelstrom
    Click on my name and send me a private message. I'd rather not do it by email. Also, you can feel free to post your .cpp files as an attachment. Infact, I'd encourage that as there are many other people on this forum that can help you better than I can.

    When I clicked your name, the site wouldn't allow me to PM you. Maybe because i just registered here like 40 minutes ago. lol

  9. #9
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Then post your attachments here. It's an option at the bottom when you post a reply.
    Sent from my iPadŽ

  10. #10
    Registered User
    Join Date
    Dec 2005
    Posts
    5
    I'll post the codes early tomorrow morning. But for now, I need a break from the computer. Sly, I hope you are around here in the morning. ..............

  11. #11
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Actually I was thinking about running away sometime late tonight... I got reclusing to do.
    Sent from my iPadŽ

  12. #12
    Registered User
    Join Date
    Dec 2005
    Posts
    5
    Hi folks.
    Sorry for the delay.

    I decided to post the codes here. Here's my "bank" menu program. The first 4 options are simple, but the last 2 options I need help with. The last 2 options are affected with the header files and the additonal .cpp files that I created, and i'm not too good at implementing these files with my menu program because I never work with them before. So, if anyone here could help me make my program seems functional, and working, that would be great.


    thanks,
    DFC

    Menu Program:

    Code:
    #include <iostream>
    #include <fstream>
    #include <string>
    #include "Account.h"
    #include "Bank.h"
    using namespace std;
    
    Bank myBank("David", "Bank for the local");
    //function prototypes
    int menu();
    void printRegister();
    void printTransaction();
    void printList();
    void printInterest();
    void printAddCustomer();
    void printFindCustomer();
    //
    //
    //Add Breakpoint to line 34
    int main()
    {
    	int choice = -1;
    	char dummy;
    	while (choice != 0)
    	{
    		choice = menu();
    
    		switch (choice)
    		{
    		case 1:
    			printRegister();
    //			cout << "choice 1 selected. press any key to continue" << endl;
    			cin >> dummy;
    			break;
    
    		case 2:
    			printTransaction();
    //			cout << "choice 2 selected. press any key to continue" << endl;
    			cin >> dummy;
    			break;
    
    		case 3:
    			printList();
    			cin >> dummy;
    			break;
    
    		case 4:
                printInterest();
    //			cout << "choice 4 selected. press any key to continue" << endl;
    			cin >> dummy;
    			break;
    
    		case 5:
    			printAddCustomer();
    			cin >> dummy;
    			break;
    
    		case 6:
    			printFindCustomer();
    			cin >> dummy;
    			break;
    
    		case 0:
    			cout << "choice 0 selected. press any key to continue" << endl;
    			break;
    
    		default:
    			cout << "not a valid choice. press any key to continue" << endl;
    			cin >> dummy;
    			break;
    		}
    	}
    	cout << "\n\n\nThanks for using my software" << endl;
    	return 0;
    }
    
    //display the main choices in a loop
    //returns when the user enter zero or 
    //any positive number
    int menu()
    {
    	int response = -1;
    	while (response < 0)
    	{
    		cout << "Miscellaneous Financial Processing" << endl;
    		cout << "         Main Menu " << endl;
    		cout << "1: Registering Applicant(s)" << endl;
    		cout << "2: Financial Transaction" << endl;
    		cout << "3: Customer List/Table" << endl;
    		cout << "4: Interest rate " << endl;
    		cout << "------------------------" << endl;
    		cout << "5: Registering Applicant(s) version 2" << endl;
    		cout << "6: Locate a registrant " << endl;
    		cout << "7. Financial Transaction (version 2) " << endl;
    		cout << "0: Quit" << endl;
    		cout << "Press the number corresponding to your choice and press enter" << endl;
    		cin >> response;
    		cin.ignore();
    	}
    	return response;
    }
    
    void printRegister()
    {
    	const int MAX = 40;             // Maximum array dimension
    	char fname[MAX];
    	char lname[MAX];
    	char bday[MAX];
    	char phone[MAX]; 
    	char acc;
    
    	char fileOut[] = "applicant.txt";
    
    	ofstream outputToFile;
    
    
    	outputToFile.open(fileOut,ios::app);
    
    	
    	
    	cout <<"This section help you fill out an application to registered for an account" << endl;
    	cout << "" << endl;
    	cout << "Please enter your first name:   " << endl;
    	cin >> fname;
    	cout << "Enter your last name:    " << endl;
    	cin >> lname;
    	cout << "Birthday (mmddyy):  ";
    	cin >> bday;
    	cout << "Your home phone number: ";
    	cin >> phone;
    	cout << "Enter the your account number (max of 5 digits): ";
    	cin >> acc;
    
    
    	outputToFile << fname << endl;
    	outputToFile << lname << endl;
    	outputToFile << bday << endl;
    	outputToFile << phone << endl;
    	outputToFile << acc << endl;
    
    	cout << "Thank you for registering. Your data is recorded in our banking records.";
    	cout << "Have a nice day.";
    	
    	outputToFile.close();
    
    }
    
    
    
    void printTransaction()
    {
    	int transelect;
    	float balance;
    	double deposit, withdraw;
    	
    	
    	cout << "This section will helps determine the state of your current balance";
    	cout << "Enter your current monetary balance:   ";
    	cin >> balance;
    
    	cout << "Choose a task:   " << endl;
    	cout << "i) Depositing" << endl;
    	cout << "ii) Withdrawing" << endl;
    	cin >> transelect;
    
    	
    	switch (transelect)
    	{
    	case 1:
    		cout << "Enter the amount you want to deposit:  ";
    		cin >> deposit;
    		cout << "You deposited $" << deposit << "from $" << balance << endl;
    		cout << "Your current balance is now $" << balance+deposit << endl;
    		break;
    	
    	case 2: 
    		cout << "Enter the amount you want to withdraw:  ";
    		cin >> withdraw;
    		cout << "You withdrawn $" << withdraw << "from $" << balance << endl;
    		cout << "Your current balance is now $" << balance-withdraw << endl;
    		break;
    	
    	}
    
    
    }
    
    void printList()
    {
    //	int fil;
    //	cout <<" This section list customer data and/or balance actions that have been processed previously" << endl;
    //	cout <<" Select the file to open the list:   " << endl;
    	string line;
    	ifstream myfile ("applicant.txt");
    	if (myfile.is_open())
    	{
    		while (! myfile.eof() )
    		{
    			getline (myfile,line);
    			cout << line << endl;
    		}
    		myfile.close();
    	}
    
    	else cout << "Unable to open file"; 
    }
    
    
    void printInterest()
    {
    	double bal, rate;
    	double result;
    	int interest;
    	int year;
    	
    
    	cout << "Enter your current balance:  $ ";
    	cin >> bal;
    	cout << "Enter enter the annual rate of your choice (no more than 9%): ";
    	cin >> interest; 
    	cout << "Enter number of years: ";
    	cin >> year;
    
    	rate = interest / 100;
    
    	result = (bal * rate) + bal * year;
    
    	cout << "Interest rate result:  " << result << " in " << year << " years";
    }
    
    void printAddCustomer()
    {
    	char fileOut[] = "registrants.txt";
    
    	ofstream outputToFile;
    
    
    	outputToFile.open(fileOut,ios::app);
    
    	
    	cout << "This process will add in new customer to the banking database" << endl;
    	char customerName[20];
    	int customerNumber;
    	cout << "Enter your last name and press enter:  ";
    	
    	cin >> customerName[20];
    	Account acct(customerName);
    	myBank.addAccount(acct);
    	outputToFile << customerName << endl;
    	
    
    	outputToFile << "Your record has been added successfully to the database" << endl;
    	
    	outputToFile.close();
    
    }
    
    
    void printFindCustomer()
    {
    	char fileOut[] = "findingcustomer.txt";
    
    	ofstream outputToFile;
    
    
    	outputToFile.open(fileOut,ios::app);
    	
    	cout << "If you are searching for a registrant, you come to the right place" << endl;
    	char customerName[35];
    	int customerNumber;
    	cout << "Enter the last name of the registrant that you are looking for, then";
    	cout << "press Enter: ";
    	cin >> customerName;
    
    	outputToFile << customerName << endl;
    
    	customerNumber = myBank.findAccounttwo(customerName);
    
    	if(customerNumber < 0)
    	{
    		outputToFile << "Sorry. We cannot locate the registrant that you are looking for. " << endl;
    	}
    	else
    	{
    		outputToFile << "Mr./Mrs./Ms  " << customerName << " is located within our database"; 
    	}
    
    	outputToFile.close();
    }

    Account.h
    Code:
    #ifndef ACCOUNT_H
    #define ACCOUNT_H
    class Account
    {
    private:
    	double balance;
    	int accountNum;
    	char fname[30];
    	char lname[30];
    public:
    	Account(char* fname, char* lname);
    	Account(char getNames);
    	Account(const int num = 0, const double balance = 0.0);
    	Account();
    	void print();
    	void deposit(int amount);
    	void withdraw(int amount);
    	int getBalance;
    };
    #endif
    Account.cpp

    Code:
    #include <iostream>
    #include "Account.h"
    using namespace std;
    
    Account::Account(char* f)
    {
    	strcpy(firstname, f);
    }
    
    Account::Account()
    {
    	strcpy(firstname, "No first name given");
    }
    
    Account::Account(char* l)
    {
    	strcpy(lastname, l);
    }
    
    Account::Account()
    {
    	strcpy(lastname, "No last name given");
    }
    
    void Account::print()
    {
    	cout << firstname << " " << lastname << endl;
    }
    
    char* Account::getNames()
    {
    	return lastname;
    }

    Bank.h

    Code:
    #ifndef BANK_H
    #define BANK_H
    #include "Account.h"
    
    class Bank
    {
    private: 
    	int customerPosition;
    	int LAST_CUSTOMER;
    	char firstname[25];
    	char lastname[25];
    	Account myAccounts[20];
    public:
    	Bank(char* firstname, char* lastname);
    	char* getNames();
    	void addAccount(Account account);
    	void addAccount(Account account, int position);
    	void addMoreAccounts();
    	void print();
    	int findAccountone(char* firstname);
    	int findAccounttwo(char* lastname);
    };
    #endif
    Bank.cpp

    Code:
    #include <iostream>
    #include "Bank.h"
    using namespace std;
    
    Bank::Bank(char* f, char* l)
    {
    	LAST_CUSTOMER = 20;
    	customerPosition = 0;
    	strcpy(firstname, f);
    	strcpy(lastname, l);
    }
    
    void Bank::print()
    {
    	cout << "Recipient's first name: " << firstname << endl;
    	cout << " + last name:  " << lastname << endl;
    	cout << "Recipient's number " << customerPosition << endl;
    	
    	for(int i = 0; i < customerPosition; i++)
    	{
    		cout << "   Rep. " << i + 1 << ":  ";
    		numberCustomers[i].print();
    	}
    }
    
    int Bank::findAccounttwo(char* l)
    {
    	for(int i = 0;i < customerPosition; i++)
    	{
    		if(strcmp(numberCustomers[i].getNames(), l) == 0)
    		{
    			return i;
    		}
    	}
    	return -1;
    }
    
    void Bank::addAccount(Account a, int position)
    {
    	if(position <= LAST_CUSTOMER)
    	{
    		myAccount[position] = c;
    	}
    }
    
    void Bank::addAccount(Account a)
    {
    	if(customerPosition <= LAST_CUSTOMER)
    	{
    		addAccount(a, customerPosition++);
    	}
    }
    
    
    void Bank::addMoreAccounts()
    {
    	Account a("David Ing");
    	addAccount(a);
    	
    	Account b("Jamie Noble");
    	addAccount(b);
    
    	Account c("John Patterson");
    	addAccount(c);
    
    	Account d("Jim Rose");
    	addAccount(d);
    
    	Account e("Werner Frei");
    	addAccount(e);
    
    	Account f("Wai Yee Ing");
    	addAccount(f);
    
    	Account g("Steve Phillips");
    	addAccount(g);
    
    	Account h("Marge Simpson");
    	addAccount(h);
    
    	Account i("Steve Jobs");
    	addAccount(i);
    
    	Account j("Mary Frown");
    	addAccount(j);
    
    	Account k("Francis Dragon");
    	addAccount(k);
    
    	Account l("James Curtis");
    	addAccount(l);
    
    	Account m("Sylvia Szawara");
    	addAccount(m);
    
    	Account n("Emma Vachan Tweeney");
    	addAccount(n);
    
    	Account o("Victor Brakter");
    	addAccount(o);
    
    	Account p("Valerie Shipton");
    	addAccount(p);
    
    	Account q("Sandra Turner");
    	addAccount(q);
    
    	Account r("Zach Ballmer");
    	addAccount(r);
    
    	Account s("Belle Lutherman");
    	addAccount(s);
    
    	Account t("Adam Clyaton");
    	addAccount(t);
    
    	Account u("Paul Hewson");
    	addAccount(u);
    
    	Account v("Bonnie Chow");
    	addAccount(v);
    
    	Account w("John Henderson");
    	addAccount(w);
    
    	Account x("Huey Freeman");
    	addAccount(x);
    
    	Account y("Heather Heeves");
    	addAccount(y);
    
    	Account z("Jackie Chan");
    	addAccount(z);
    }

  13. #13
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    I'd like to add that I said via PM he could bump this (or start a new post) because I didn't have time to look at the code for him.
    Sent from my iPadŽ

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  2. Linking header files, Source files and main program(Accel. C++)
    By Daniel Primed in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 11:46 AM
  3. Replies: 4
    Last Post: 12-14-2005, 02:21 PM
  4. header and source files
    By gtriarhos in forum C Programming
    Replies: 3
    Last Post: 10-02-2005, 03:16 AM