cpp Assignment help

In this assignment you will be modeling a part of simple banking system. In this system, there are two classes, Customer and Account which are related to each other via aggregation relationship.



Account class has the following data members:
 Account No.
 Current Balance
 Bank name
 Branch code


Account class must have the following member functions:

Function Description
Account() Default constructor for account class, setting account balance to 0, Account number to 1, branch name to NULL and branch code to 0
Account(float, int, char *, int) It will take balance, account no, bank name and branch code as arguments and set their values accordingly
withdraw(float) This will subtract amount from the balance of account that will be passed as its parameter.
If the amount being withdrawn is greater the balance of the account , it will display the message “Insufficient balance”
deposit(float) Function will add amount to the balance of account. Amount will be passed as its parameter.
getBalance() This function will return the value of available balance
getAccountNo() This function will return the account number
getBankName() This function will return the name of bank
getBrachCode() This function will return branch code of bank

Customer class has the following data members:
 Customer Name
 Address
 Account object

Customer class must have the following member functions:

Function Description
display() This function will display the values of all data members of Customer and Account class
Parameterized constructor It will take Account, name and address as a arguments and set their values accordingly


Within main() function, objects of both classes will be created , and respective member functions of these objects will be called.

First of all create an object of Account class by passing balance, account number, bank name and branch code. Then create an object of customer class by passing Account object, name and address. Now call display() function which will display all the values of Customer including his/her name, address and account detail.

The program should prompt the user to enter a value and call deposit() function passing it entered value. Then call the display() function.

After this, the program should prompt the user to enter a value and call withdraw() function passing it entered value. Then call the display() function.

Sample output of the program:


Please post what you have tried, what you have difficulties with, and any questions you have. We can't read your mind and all we see is a copy/pasted assignment.
there is error in first line. and if u add appropriate comment after important line.that'll be good.

#include <iostream.h>
using namespace std;

// Account Class Declaration and Definition
class account{
private:
int accountNo;
float balance;
string bankName;
int b_code;
public:
account(){ // Default Constructor
accountNo=00;
balance=0.0;
bankName="Default";
b_code=00;
} // End of Default Constructor

account(int ac_num, float bal, string b_name, int code){ // Parametarized Constructor
accountNo=ac_num;
balance=bal;
bankName=b_name;
b_code= code;
} // End Parametarized Constructor

void withdraw(float draw_money){ // WithDrawl Func
if (balance<draw_money){
cout << "\n\a \"Insufficient balance.......\"";
}
else{
balance-=draw_money;
}
} // End of WithDrawl Func

void deposit(float add_money){ // Deposit Func
balance+=add_money;
}
// And other some self explanatory Function of Account Class
float getBalance(){
return balance;
}
int getAccountNo(){
return accountNo;
}
string getBankName(){
return bankName;
}
int getBrachCode(){
return b_code;
}
}; // End of Account Class

class customer{
private:
string name;
string address;
public:
account ac; // public because it is represented as public in class diagram
customer(string n, string a, account acc){ // Parametarized Constructor
name= n;
address=a;
ac=acc;
} // End of Parametarized Constructor

void display(){
cout << "\n Customer Name: "<<name;
cout << "\n Customer Address: "<<address;
cout << "\n Bank Name: "<<ac.getBankName();
cout << "\n Branch Code: "<<ac.getBrachCode();
cout << "\n Current Balance: "<<ac.getBalance();
cout << "\n Account No. "<<ac.getAccountNo();
}
}; // End of Customer Class

main(){
cout << "..........Displaying Customer Account Information........."<<endl<<endl;
account myaccount(7812, 40000, "Askari Bank", 123); // Creating an account Obj
customer DD("Double Diamond", "Programming Island", myaccount); // Creating an customer Obj
DD.display();

float dep, draw;
cout << "\n\n Please Enter a value for Deposit: ";
cin >> dep;
DD.ac.deposit(dep);
cout << "\n\n Current Balance after Depositing...";
DD.display();

cout << "\n\n Please Enter a value for Withdrawl: ";
cin >> draw;
DD.ac.withdraw(draw);
cout << "\n\n Current Balance after withdrawing...";
DD.display();

cout << endl<<endl;
system("pause");
}
The error in line 1 is the name of the header file you are looking for is iostream, not iostream.h.

Let me give you some pointers about how to ask us for help. Asking the right questions will get you better answers more quickly.

1. When you paste code into your posts, use code tags. The code tags make it easier for us to read your code because, among other things, they preserves indentation. They also provide line number, so it is easier for us to comment on your code. The easiest way to add the tags is to click the Format button that has the "<>" symbol. This will put the opening and closing tag into your post. Merely paste your code between the tags.

2. Give us as much information about errors as you can. Stating
there is error in first line
points us in the right direction, but pasting the actual errors from the compiler output would give us a lot more information from which to make informed comments.

3. Be as specific as possible with your questions. It is far better to ask about a specific place where you are stuck than to paste 100 lines of code and ask us to comment on all the places that we see problems. Pick one problem (or maybe two) at a time and ask for help. As we help you get past a problem, that information may help you with your next problem. If not, ask another question. This iterative (one step at a time) development approach is usually better than a single "big bang" approach to software development, and you should get used to building up your programs in small, bite-sized chunks. And when you have a problem at a specific chunk, we can help--that's what we're here for.
thanks mate
having another error in other program

#include <iostream>
#include <stdlib.h>
using namespace std;

class Patient{
private:
char * name;
int age;

public:
Patient(){
name=NULL;
age=0;
}
Patient(char* n, int a){
name = new char[strlen(n)+1];
strcpy(name,n);
age = a;
}

void setPatient(char* n, int a){
name = new char[strlen(n)+1];
strcpy(name,n);
age = a;
}

char* getName(){
return name;
}
int getAge(){
return age;
}


};

class PatientQueue{
private:
Patient array[10];
int rear;
int size;
int front;
int noOfElement;
public:
PatientQueue(){
rear=0;
front = 0;
size = 10;
noOfElement = 0;
}

void Add_Patient(Patient p){
array[rear] = p;
rear = (rear + 1) % size;
noOfElement++;
}

int isFull(){
return noOfElement==size;
}

int isEmpty(){
return noOfElement == 0;
}

int getSize(){
return noOfElement;
}

Patient dequeue(){

Patient x = array[front];
front = (front + 1)%size;
noOfElement = noOfElement - 1;
return x;
}
};

int main(int argc, char** argv) {
int x =0;
char * n = new char[50];
int a;
Patient p;
PatientQueue A;
PatientQueue B;

char choice1,choice2;

do{

cout<< "Menu"<<endl;
cout<< "\n1: Register a new Patient"<<endl;
cout<< "\n2: Display List of Patient treated by Physician A" <<endl;
cout<< "\n3: Display List of Patient treated by Physician B" <<endl;
cout<< "\n4: Display Total Number of Patients served" <<endl;
cout<< "\n5: Exit" <<endl;

cout<<"******************************************"<<endl;
cout<<"\nEnter Your Choice: ";
cin>>choice1;

switch(choice1){
case '1' : {
do{
cout<<"Enter Patient Name: ";
cin>>n;
cout<<"Enter Patient Age: ";
cin>>a;
p.setPatient(n,a);
x++;
if(a<50){
A.Add_Patient(p);
}
else{
B.Add_Patient(p);
}
cout<<"Do you want to continue y/n: ";
cin>>choice2;

}while((choice2)=='y');

break;
}

case '2' :{
Patient temp;
while(!A.isEmpty()){
temp = A.dequeue();
cout<<"\nTotal Patient Served by Physician A."<<endl;
cout<<"Name: "temp.getName()"\nAge: " <<temp.getAge()endl;
}

break;
}

case '3' : {
Patient temp;
while(!B.isEmpty()){
temp = B.dequeue();
cout<<"\nTotal Patient Served by Physician A."<<endl;
cout<<"Name: "temp.getName()"\nAge: "temp.getAge()<<endl;
}

break;
}

case '4': {

cout<<"\nTotal Patient Served by Physician A and Physician B: "<<endl;
break;
}

case '5' :{
cout<<"\nThanks for using this program\n";
break;
}

default:
cout<<"Wrong Input"<<endl;
}

cout<<"\n\nDo you want to back Menu y/n: ";
cin>>choice2;

}while((choice2)=='y');

if(choice2=='n')
cout<<"\nThanks for using this program\n";



return 0;
system("pause");
}

bugs are :
C:\Users\-(Victor)-.-Victor-PC\Desktop\cs301-2.cpp In function `int main(int, char**)':
130 C:\Users\-(Victor)-.-Victor-PC\Desktop\cs301-2.cpp expected `;' before "temp"
141 C:\Users\-(Victor)-.-Victor-PC\Desktop\cs301-2.cpp expected `;' before "temp"
i got an hour left guys,
Are all this code in just 1 file? If not, maybe you forgot to include the header file where Patient class is defined into the source file where main() program is
so hich header file should i use? i fixed the "temp" issue now it says
131 C:\Users\-(Victor)-.-Victor-PC\Desktop\cs301-2.cpp expected `;' before string constant

what is string constant in cout<<"Name: " ; temp.getName()"\nAge: " <<temp.getAge()endl;
i got an hour left guys,

Whose fault is that? We can try to help you, but since you don't sign my paychecks, you take a lower priority than my work responsibilities.


Thank-you for pasting the error messages. That helps. However, since you ignored my comment about using code tags, I have no idea which is line 130 and which is line 141.

It looks like there are statements on or just before line 130 and 141 (I don't have time to count the lines to identify them properly) that are missing their terminating ';'. They could also be a syntax error that the compiler thinks looks like one statement should have ended and a second was beginning.

The error message has enough information in it to help you figure out where the error is and enough description to hint at what might be wrong.
just tell me which one is a string constant in this line. it should solve the problem
cout<<"Name: " << temp.getName() <<" \nAge: " << temp.getAge() << endl;

Last edited on
1
2
cout << "Name: " << temp.getName() << "\nAge: " << temp.getAge() << endl;
                 ^^                ^^                            ^^
Topic archived. No new replies allowed.