strong text
As I am trying to code a program for ATM SYSTEM ,I am facing a problem with the array of objects
for values/data getting overridden for all the objects by the last object data/values means, the values of the first and middle objects are getting replaced by the values or data of the last object as i go on accepting values for the next objects in the array i am trying, to use the array of objects in the program to make my code get as minimized as possible.
Please Help me here, How to solve the point in the code. I will Solve it again with your best Suggestion.
#include <iostream>
#include <string>
#include <vector>
using namespace std;
string Card_no,Account_no,Person_name;
long int Pin_no,num;
class Login
{
private :
public :
void setPerson_name(string D)
{
Person_name = D;
}
void setAccount_no(string C)
{
Account_no = C;
}
void setCard_no(string A)
{
Card_no = A;
}
void setPin_no(long B)
{
Pin_no = B;
}
string getPerson_name()
{
return Person_name;
}
string getAccount_no()
{
return Account_no;
}
string getCard_no()
{
return Card_no;
}
int getPin_no()
{
return Pin_no;
}
void accept_customer_details()
{
string person_name,account_number,card_number;
long int pin_number;
cout<<"\n Accepting Employee Details : \n"<<endl;
cout<<"Enter the Person Name : "<<endl;
cin>>person_name;
cout<<"Enter the Account Number of the Person : "<<endl;
cin>>account_number;
cout<<"Enter the 16 digit ATM Card Number of the Person : "<<endl;
cin>>card_number;
cout<<"Enter the 4 digit ATM PIN NUMBER : "<<endl;
cin>>pin_number;
setPerson_name(person_name);
setAccount_no(account_number);
setCard_no(card_number);
setPin_no(pin_number);
}
void display_customer_details()
{
string pnm,an,cn;
int pn;
pnm = getPerson_name();
an = getAccount_no();
cn = getCard_no();
pn = getPin_no();
cout<<"\n Displaying the Employee details : \n"<<endl;
cout<<"The Person's Name : "<<pnm<<endl;
cout<<"The Account Number of the Person : "<<an<<endl;
cout<<"The 16 digit ATM Card Number of the Person : "<<cn<<endl;
cout<<"The 4 digit ATM PIN NUMBER : "<<pn<<endl;
}
};
class Access : public Login
{
public :
void account_ass(vector <Login> &VL,int sz)
{
num = sz;
Login l[num];
string ucn,upn;
//string CARD_NUMBER[sz],PIN_NUMBER[sz],ACC_NO[sz],P_NAME[sz];
int flag0 = 0,flag1 = 0,flag2 = 0,flag02 = 0;
int chance = 3,c = 0,p = 0;
for(int o = 0;o<num;o++)
{
cout<<"value of o is : "<<o<<endl;
l[o] = VL[o];
cout<<"\n CARD_NUMBER IS HERE : "<<l[o].getCard_no()<<"\n AND ITS PIN NUMBER IS : "<<l[o].getPin_no()<<endl;
cout<<"The Account Number is : "<<l[o].getAccount_no()<<" \n Person's Name is : "<<l[o].getPerson_name()<<endl;
cout<<"Object :"<<o+1<<" address : "<<&l[o]<<endl;
}
}
};
int main()
{
int N;
cout<<"Enter how many person's details you want to add :- "<<endl;
cin>>N;
Login lg[N];
//Access ac[N];
vector <Access> ac;
Access a;
vector <Login> vl;
for(int K = 0;K<N;K++)
{
ac[K].accept_customer_details();
}
for(int I=0;I<N;I++)
{
ac[I].display_customer_details();
vl.push_back(ac[I]);
}
a.account_ass(vl,N);
return 0;
}