Lab 6 Details of N Students. / C++ Program To Demonstrate Example of Array of Objects
Lab 6 Details of N Students. / C++ Program To Demonstrate Example of Array of Objects
#define MAX 10
class student
{
private:
char name[30];
int rollNo;
int total;
float perc;
public:
void getDetails(void);
void putDetails(void);
};
void student::getDetails(void){
cout << "Enter name: " ;
cin >> name;
cout << "Enter roll number: ";
cin >> rollNo;
cout << "Enter total marks outof 500: ";
cin >> total;
perc=(float)total/500*100;
}
void student::putDetails(void){
cout << "Student details:\n";
cout << "Name:"<< name << ",Roll Number:" << rollNo
<< ",Total:" << total << ",Percentage:" << perc;
}
int main()
{
student std[MAX];
int n,loop;
for(loop=0;loop< n; loop++){
cout << "Details of student " << (loop+1) << ":\n";
std[loop].putDetails();
}
return 0;
}
Data members:
1) Name of the depositor
2) Account number
3) Type of account
4) Balance amount in the account.
Member functions:
1) To assign initial values
2) To deposit an amount
3) To withdraw an amount after checking the balance
4) To display name and balance.
class bank
{
int a;
char nm[100], acctype[100];
float bal;
public:
bank(int a_n, char *name, char *acc_type, float
balance)
{
a=a_n;
strcpy(nm, name);
strcpy(acctype, acc_type);
bal=balance;
}
void deposit();
void withdraw();
void display();
};
void bank::deposit()
{
int damt1;
cout<<"\n Enter Deposit Amount = ";
cin>>damt1;
bal+=damt1;
}
void bank::withdraw()
{
int wamt1;
cout<<"\n Enter Withdraw Amount = ";
cin>>wamt1;
if(wamt1>bal)
cout<<"\n Cannot Withdraw Amount";
bal-=wamt1;
}
void bank::display()
{
cout<<"\n ----------------------";
cout<<"\n Accout No. : "<<a;
cout<<"\n Name : "<<nm;
cout<<"\n Account Type : "<<acctype;
cout<<"\n Balance : "<<bal;
}
int main()
{
int acc_no;
char name[100], acc_type[100];
float balance;
cout<<"\n Enter Details: \n";
cout<<"-----------------------";
cout<<"\n Accout No. ";
cin>>acc_no;
cout<<"\n Name : ";
cin>>name;
cout<<"\n Account Type : ";
cin>>acc_type;
cout<<"\n Balance : ";
cin>>balance;