Friday, March 26, 2010

Basic OOPS concept Ques 4(Account)

#include iostream.h
#include conio.h
#include stdio.h

class account
{
private:
int accountno;
long balance_amount;
char name[25];
public:
void getdata();
int transaction(char,long,long&,long&);
int check_account(int);
void show_balance();
};

void account::getdata()
{
cout<<"Name: "; gets(name);
cout<<"Account no.: "; cin>>accountno;
cout<<"\nAccount Balance "; cin>>balance_amount;
cout<}

int account::transaction(char ans, long tran_amount,long &totwith, long &totdep)
{
int f=1;
if(ans=='w')
{
if(balance_amount-tran_amount<=100)
f=-1;
else
{
balance_amount-=tran_amount;
totwith+=tran_amount;
}
}
else if(ans=='d')
{
balance_amount+=tran_amount;
totdep+=tran_amount;
}
return(f);
}

int account::check_account(int accno)
{
int flag=0;
if(accountno==accno)
flag=1;
return(flag);
}

void account::show_balance()
{
cout<<"\nName: "; puts(name);
cout<<"Remaining Balance: "; cout<}

void main()
{
clrscr();
int accno, f, flag, k=-1;
long tran_amt, totalwith=0, totaldep=0;
char ans, ch;
account acc[2];

cout<<"Enter Details..\n";
for( int i=0; i<2; i++)
{
cout<<"Person "< acc[i].getdata();
}
cout<<"\nDo you want to make a transaction(y/n)? ";
cin>>ch;

while(ch=='y')
{
cout<<"Enter account no.: ";
cin>>accno;

for(i=0; i<2; i++)
{
flag=acc[i].check_account(accno);
if(flag==1)
{
k=i;
break;
}
}
if(flag==0)
{
cout<<"Account not found!!";
f=-1;
}
if(k!=-1 && k<2)
{
cout<<"\nWhat do you want to do??\n Withdrwal(w) or Deposit(d) ";
cin>>ans;

cout<<"\nEnter transaction amount: ";
cin>>tran_amt; cout<
f=acc[k].transaction(ans, tran_amt, totalwith, totaldep);
}

if(f==-1)
cout<<"\nTransaction Unsuccesful!!\a";
else
cout<<"\nTransaction Successful!!";

cout<<"\n\nDo you want to make another transaction(y/n)?? ";
cin>>ch;
}
for(i=0; i<2; i++)
acc[i].show_balance();

cout<<"\nTotal withdrawal: "< cout<<"\nTotal deposit: "< getch();
}

Wednesday, March 24, 2010

Basic OOPS concept Ques 3(LIBRARY)

#include
#include
#include

class library
{
private:
int bookno, no_of_copies, no_of_copies_issued;
char bookname[20];
float price;

public:
void getdata();
int issue(int);
void returnbk(int);
void showdata(int);
};

void library::getdata()
{
cout<<"Book name: ";
gets(bookname);

cout<<"Book no.: "; cin>>bookno;
cout<<"\nTotal no of copies: "; cin>>no_of_copies;
cout<<"\nCopies issued: "; cin>>no_of_copies_issued;
puts("\nPrice: ");
cin>>price;
}

int library::issue(int bkno)
{
int f=0;
if(bookno==bkno)
{ f=1;
if(no_of_copies-no_of_copies_issued>0)
{
cout<<"\nBook Issued";
no_of_copies_issued++;
}
}
else
cout<<"\nBook out of stock!!";
return(f);
}

void library::returnbk(int bkno)
{
if(bookno==bkno)
{
cout<<"\nBook returned";
no_of_copies_issued--;
cout<<"\nTotal book available for issuing: "< }
}

void library::showdata(int bkno)
{
if(bookno==bkno)
{
cout<<"\nBook no.::"< cout<<"Name: "; puts(bookname);
cout<<"Total copies available in Library: "< cout<<"\nCopies issued: "< cout<<"\nPrice: Rs."< }
}

void main()
{
clrscr();
int bkno, ch;
library bk[5];

for(int i=0; i<5; i++)
{
cout<<"Enter details of "< bk[i].getdata();
cout<}

cout<<"1.Issue a book.\n2.Return a book\n3.Print Details\nEnter choice...";
cin>>ch;

switch(ch)
{
case 1: int f;
cout<<"Enter book no.";
cin>>bkno;
for(int i=0; i<5; i++)
{
f=bk[i].issue(bkno);
if(f==1)
break;
}
if(f==0)
cout<<"Book not found";
break;

case 2: cout<<"Enter book no.";
cin>>bkno;
for(i=0; i<5; i++)
bk[i].returnbk(bkno);
break;

case 3: cout<<"Enter book no.";
cin>>bkno;
for(i=0; i<5; i++)
bk[i].showdata(bkno);
break;

default: cout<<"Wrong choice!!\a\a";
}
getch();
}

Basic OOPS concept Ques 1(My Folder)

#include
#include
#include

class myfolder
{
private: char filename[10][25];
long totspace();
long usedspace();
public: void newentry();
void showfiles();
float retspace();
};

void myfolder::newentry()
{
cout<<"Enter flenames:\n";
for(int i=0; i<10;>
gets(filename[i]);
cout<
}

long myfolder::totspace()
{
long t=10*25*1;
return(t);
}

long myfolder::usedspace()
{
long j, space=0;
for(int i=0; i<10;>
{
j=0;
while(filename[i][j]!='\0')
{
space++;j++;
}
space++;

}
return(space);
}

float myfolder::retspace()
{
long tot= totspace();
long used= usedspace();
float kb= float(tot-used)/1024;
cout<<"Total space="<<<" bytes."<
cout<<"Used space="<<<" bytes."<
return(kb);
}

void myfolder::showfiles()
{
for(int i=0; i<10;>
{
cout<<<". ";
puts(filename[i]);
}
}

void main()
{
clrscr();
int n;
float KB=0;
myfolder mf;

mf.newentry();

KB=mf.retspace();
cout<<"Total space available is "<<< "KB."<<

mf.showfiles();
getch();
}