For my programming class I must create a simple banking program with a DB in Array. I've got all that working great. But I'm stuck at one of the points in the task - each function must be in a separate header file.
Can someone help me move one of the functions to a header? :)
#include <iostream>
usingnamespace std;
struct clientData
{
int accNum;
char Sur[15];
char Name[10];
float balance;
voidoperator=(clientData * c)
{
accNum = c->accNum;
for(int i=0;i<15;i++)
Sur[i] = c->Sur[i];
for(int i=0;i<15;i++)
Name[i] = c->Name[i];
balance = c->balance;
}
};
class base
{
clientData * cl;
int maxSize;
int count;
public:
base()
{
maxSize = 100;
cl = new clientData[maxSize];
count = 0;
}
~base()
{
delete cl;
}
void add();
void print();
void del();
void find();
void setBalance();
void printDoubt();
void printCount();
char PrintMenu();
};
void base::printCount()
{
//Function to print out number of clients
}
void base::add() //To add a new client
{
cout<<"Input Surname:";
cin>>cl[count].Sur;
cout<<"Input Name:";
cin>>cl[count].Name;
cout<<"Input Balance:";
cin>>cl[count].balance;
cl[count].accNum = count;
count++;
}
void base::print()
{
//Function to print out all client data
}
void base::del()
{
//Function to delete client
}
void base::setBalance()
{
//Function to change balance
}
void base::find()
{
//Function to find client based on accNum
}
void base::printDebt()
{
//Function to print clients with debt
}
char base::PrintMenu()
{
char a;
cout<<"1: Add client"<<endl;
cout<<"2: Deelete client"<<endl;
cout<<"3: Print all clients"<<endl;
cout<<"4: Find client"<<endl;
cout<<"5: Edit balance"<<endl;
cout<<"6: Print client with debt"<<endl;
cout<<"7: Print count of clients"<<endl;
cout<<"q: Quit"<<endl;
cin>>a;
return a;
}
int main()
{
base * b = new base;
while(true)
{
switch(b->PrintMenu())
{
case'1':b->add(); break;
case'2':b->del(); break;
case'3':b->print(); break;
case'4':b->find(); break;
case'5':b->setBalance(); break;
case'6':b->printDoubt(); break;
case'7':b->printCount(); break;
case'q':exit(1); break;
default: cout<<"Incorrect letter"; break;
}
}
}
Here is what I try to do it:
1: Make add.h and add.cpp files to move the function to add a client
2: Add #include "add.h" to the main file
3: Move this to add.cpp
Here is the whole task (translated from Latvian, since the class is in Latvian)
Based on this structure:
struct clientData // client Data
{
int accNum; // account number
char Sur[15]; // surname
char Name[10]; // name
float balance; // balance
};
Create database in form of an array. There must be a main menu with such entries:
* Add entry
* Delete entry
* Print out all entries
* Find an entry (by account number)
* Change account balance (find account by number and input a value to add to the balance)
* Show all clients with debt
* Count entries
* Exit
Additionaly the program should have this:
* Account number must be the index value
* Array size - 100 entries
* Each operation must be in a separate funktion * Each function must be in a separate header file
* After each operation the user has to be taken back to the main menu.
More or less I have everything except that each function must be in a separate file.