Categories
Uncategorised

Classes – Admission Process

/* Copyright (C) 2007 Ankur Banerjee. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. http://www.fsf.org/licensing/licenses/lgpl.html /

/ WAP to administer admission process. Define a class ‘admission’ with private members admno (int), name (string), classes (char), fee (float); public members functions readdata() to input data, disp() to display data, drawnos() to choose two students randomly. WARNING: The following program might take a long time to reach completion at the draw numbers stage – it is not an infinite loop problem but until two students are chosen the loop will keep on running, resulting in long program execution time. */

#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>

int i, flag = 1;

class admission
{
int admno;
char name[50], classes; // variable name class cannot be used since it is a keyword
float fee;
public:
void readdata()
{
cout<<endl<<“Enter data for student “<<i + 1
<<endl<<“Enter admission number : “;
cin>>admno;
cout<<“Enter name of student : “;
gets(name);
cout<<“Enter section of student : “;
cin>>classes;
cout<<“Enter fees submitted by student : “;
cin>>fee;
}
void disp()
{
cout<<“Displaying data for student”<<endl
<<“Admission number : “<<admno<<endl
<<“Student name : “<<name<<endl
<<“Section : “<<classes;
}
void drawnum()
{
int n1;
randomize();
n1 = random(1991) + 10;
if (( n1 == admno) && (flag < 3))
{
disp();
flag++;
}
}
} s[5];

void main()
{
clrscr();
cout<<endl<<“Admission Process Management Program”<<endl
<<“Enter initial data for all students”<<endl;
for (i = 0; i < 5; i++)
s[5].readdata();
cout<<endl<<“Randomly choosing students for admission”<<endl;
do
{
for (i = 0; i < 5; i++)
s[i].drawnum();
} while (flag < 3);
cout<<endl<<“Two students have been chosen randomly out of database”<<
getch();
}

Categories
Uncategorised

Classes – Accounts

/* Copyright © 2007 Ankur Banerjee. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. http://www.fsf.org/licensing/licenses/lgpl.html /

/ Classes – Program to manage accounts /

#include <iostream.h>
#include <conio.h>
#include <stdio.h>

int i, n, amt;
char tran;

class account
{
int num;
char name[50];
float bal;
static float tot, totd, totw;
public:
void accept()
{
cout<<endl<<“Enter data for account “<<i + 1<<endl
<<“Enter account number : “;
cin>>num;
cout<<“Enter account name : “;
gets(name);
cout<<“Enter balance amount : “;
cin>>bal;
}
void disp(int no)
{
if (no == num)
{
cout<<endl<<“Displaying data for requested “<<“account”
<<endl<<“Accountnumber : “<<num<<endl
<<“Account name : “<<name<<endl
<<“Account balance : “<<bal;
}
}
void trans(int no, char t, float a)
{
if (no == num)
{
if (t == ‘d’)
{
bal += a;
totd += a;
}
else if (t == ‘w’)
{
bal -= a;
totw += a;
}
}
tot = totd – totw;
}
static void total()
{
cout<<endl<<“Total deposits by all account holders : “<<totd<<endl
<<“Total withdrawals made by all account holders : “<<totw<<endl
<<“Total of all transactions done by all account holders : “<<tot;
}
} acc[5];

float account::tot = 0.0;
float account::totd = 0.0;
float account::totw = 0.0;

void main()
{clrscr();
int ch;
char choice;
cout<<endl<<“Account Management Program\n \n”
<<“Enter initial details for all accounts”<<endl;
for (i = 0; i < 5; i++)
acc[i].accept();
do
{
cout<<endl<<“Program Menu”<<endl
<<“1. Display data for particular account”<<endl
<<“2. Carry out transaction”<<endl
<<“3. Display total withdrawal and total deposits”<<endl
<<“Enter your choice : “;
cin>>ch;
if
(ch == 1)
{
cout<<endl<<“Enter account number for required account : “;
cin>>n;
for (int i = 0; i < 10; i++)
acc[i].disp(n);
}
else if (ch == 2)
{
cout<<endl<<“Enter account number associated with transaction : “;
cin>>n;
cout<<“Enter type of transaction – d for deposit and w for withdrawal : “;
cin>>tran;
cout<<“Enter transaction amount : “;
cin>>amt;
for (i = 0; i < 5; i++)
acc[i].trans(n, tran, amt);
cout<<“Account balance for account number “<<n
<<” has been updated”;
}
else if (ch == 3)
{
acc[0].total();
}

else cout<<endl<<“You entered an incorrect choice”;
cout<<“\n \nDo you wish to continue – y / n : “;
cin>>choice;
} while (choice == ‘y’ || choice == ‘Y’);
cout<<endl;
getch();
}

/ Output */

Account Management Program

Enter initial details for all accounts

Enter data for account 1
Enter account number : 42
Enter account name : Ankur Banerjee
Enter balance amount : 875

Program Menu
1. Display data for particular account
2. Carry out transaction
3. Display total withdrawal and total deposits
Enter your choice : 1

Enter account number for required account : 42

Displaying data for requested account
Account number : 42
Account name : Ankur Banerjee
Account balance : 875

Program Menu
1. Display data for particular account
2. Carry out transaction
3. Display total withdrawal and total deposits
Enter your choice : 2

Enter account number associated with transaction : 42
Enter type of transaction – d for deposit and w for withdrawal : d
Enter transaction amount : 420

Account balance for account number 42 has been updated

Program Menu
1. Display data for particular account
2. Carry out transaction
3. Display total withdrawal and total deposits
Enter your choice : 3

Total deposits by all account holders : 420
Total withdrawals made by all account holders : 0
Total of all transactions done by account holders : 420