0% found this document useful (0 votes)
98 views41 pages

Coding of Project

This C++ program defines a Tenant class to store tenant information such as name, address, rental payment details. The class contains methods to get, put, modify and generate a tenant ID for data. Additional functions allow users to add, edit, delete tenant records from a binary data file, and view rental reports. The program provides a basic property management system to organize tenant information.

Uploaded by

Akshara Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
98 views41 pages

Coding of Project

This C++ program defines a Tenant class to store tenant information such as name, address, rental payment details. The class contains methods to get, put, modify and generate a tenant ID for data. Additional functions allow users to add, edit, delete tenant records from a binary data file, and view rental reports. The program provides a basic property management system to organize tenant information.

Uploaded by

Akshara Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 41

#include<fstream.

h>
#include<conio.h> //For console input-output functions.
#include<stdio.h> //For standard input-output functions.
#include<stdlib.h> //For free();,etc.
#include<process.h> //For exit();
#include<iomanip.h> //For hex();,etc.
#include<string.h> //For strcmpi();,etc.
int i;
void About();
void ViewReport();
/* -----------------------------------------------------------------------------
CLASS NAME : Tenant
DETAILS : IT CONTAINS ALL INFORMATION REGARDING
THE TENANT AND HIS/HER BACKGROUND
--------------------------------------------------------------------------------
*/
// class starts
class tenant //Program starts.
{
private: //declaring variables
char Name[40];
char Father[57];
int Flat;
char Block;
int Age;
int Maintenance;
char PermAddress[100];
char Occupation[20];
char ContactNo[11];
char Description[100];
char CriminalRecord[50];
char witnessname[25];
void generate();

public:

char TenantID[10];
long DueAmount;
char Bock();
char* checkID();
int Rent();
void getdata();
void putdata();
void modif();
void PrintSumary();
void PrintSummary();
}; //class ends.

void tenant::getdata() //function to get data.


{
lb7:
cout<<"\n Tenant Name -> ";
gets(Name);
cout<<"\n Father Name -> ";
gets(Father);
lb99:
cout<<"\n Flat Number(1-150) -> ";
cin>>Flat;
if(Flat<1||Flat>150)
{
cout<<"\nKindly mention flat numbers acc. to range mentioned

above ";
cout<<"\nEnter the flat number again";
goto lb99;
}
cout<<"\nBlock Name(A/B/C) -> ";
cin>>Block;
generate();
cout<<"\nMaintenance Paid(Rs) -> ";
cin>>Maintenance;
cout<<"\n Tenant Age(19-85) -> ";
cin>>Age;
if(Age<18||Age>85)
{
cout<<"\nSorry!! we give flats on rent only to people of age

group b/w 19-85";


cout<<"\nEnter the new record again";
goto lb7;
}
cout<<"\n Occupation -> ";
gets(Occupation);
cout<<"\n Rent paid(Rs) -> ";
cin>>DueAmount;
cout<<"\n Permanent Address -> ";
gets(PermAddress);
lb:
cout<<"\n Contact No -> ";
gets(ContactNo);
if(strlen(ContactNo)!=10)
{cout<<"\nSorry, phone number must have 10 digits";
goto lb;}
cout<<"\n Description of person -> ";
gets(Description);
cout<<"\n Criminal Record (if any) -> ";
gets(CriminalRecord);

cout<<"\n*****************************************************

*********";
cout<<"\nYour Tenant ID is: "<<TenantID<<endl;
}
void tenant::putdata() //function to display data.
{ char ch,gh;

cout<<"\n*****************************************************

*********";
cout<<"\n Tenant ID: "<<TenantID;
cout<<"\n Name: "<<Name;
cout<<"\n Father name: "<<Father;
cout<<"\n Tenant Age; "<<Age;
cout<<"\n\n To see personal info press 'Y' else 'N'";
ch=getche();
if(ch=='y'||ch=='Y')
{
cout<<"\n Permanent Address: "<<PermAddress;
cout<<"\n Occupation: "<<Occupation;
cout<<"\n ContactNo: "<<ContactNo;
cout<<"\n Description: "<<Description;
cout<<"\n Criminal Record: "<<CriminalRecord;
}
cout<<"\n\n To see flat info press 'Y' else 'N'";
gh=getche();
if(gh=='y'||gh=='Y')
{
cout<<"\n Flat Number: "<<Flat;
cout<<"\n Block : "<<Block;
cout<<"\n Rent Paid: "<<DueAmount;
cout<<"\n Maintenance :"<<Maintenance;
}

}
void tenant::modif() //function to modify data.
{ lb8:
cout<<"\n Tenant Name -> ";
gets(Name);
cout<<"\n Father Name -> ";
gets(Father);
lb99:
cout<<"\n Flat Number(1-150) -> ";
cin>>Flat;
if(Flat<1||Flat>150)
{
cout<<"\nKindly mention flat numbers acc. to range mentioned

above ";
cout<<"\nEnter the flat number again";
goto lb99;
}
cout<<"\nBlock Name(A/B/C) -> ";
cin>>Block;
cout<<"\nMaintenance Paid(Rs) -> ";
cin>>Maintenance;
cout<<"\n Tenant Age(19-85) -> ";
cin>>Age;
if(Age<18||Age>85)
{
cout<<"\nSorry!! we give flats on rent only to people of age

group b/w 19-85";


cout<<"\nEnter the new record again";
goto lb8;
}
cout<<"\n Occupation -> ";
gets(Occupation);
cout<<"\n Rent paid(Rs) -> ";
cin>>DueAmount;
cout<<"\n Permanent Address -> ";
gets(PermAddress);
lb:
cout<<"\n Contact No -> ";
gets(ContactNo);
if(strlen(ContactNo)!=10)
{cout<<"\nSorry phone number must have 10 digits";
goto lb;}
cout<<"\n Description of person -> ";
gets(Description);
cout<<"\n Criminal Record (if any) -> ";
gets(CriminalRecord);
}
void tenant::generate() //function to generate tenant ID.
{char k[10];
randomize();
if(Block=='A'||Block=='a'||Block=='B'||Block=='b')
{for(i=0;i<5;i++)
{
k[i]=65+random(26);
}
k[5]='\0';
strcpy(TenantID,"123");
strcat(TenantID,k);
}
else
{ for(i=0;i<5;i++)
{
k[i]=97+random(26);
}
k[5]='\0';
strcpy(TenantID,"123");
strcat(TenantID,k);
}
}
void tenant::PrintSumary() //function to show summary of a tenant.
{ cout<<endl<<TenantID<<" \t\t"<<Name<<"\t

\t"<<Father<<"\t\t"<<DueAmount;
}
void tenant::PrintSummary()
{ cout<<endl<<Block<<"\t\t"<<TenantID<<" \t

\t"<<Name<<"\t\t"<<Flat<<"\t\t"<<Maintenance;
}
char* tenant::checkID()
{return TenantID;
}
int tenant::Rent()
{
return Maintenance;
}
char tenant::Bock()
{
if(Block=='a')
{Block='A';}
if(Block=='b')
{Block='B';}
if(Block=='c')
{Block='C';}
return Block;
}
void AddRecord() //function to add records of new tenant.
{ clrscr();
tenant T;
ofstream file;
cout<<"\n --- ENTER THE INFORMATION FOR A NEW

RECORD ---";

cout<<"\n---------------------------------------------------------------------------"

;
file.open("Tenant.dat",ios::binary|ios::out|ios::app); //To open

file.
T.getdata();
file.write((char*)&T,sizeof(T)); //To read data.
file.close();
cout<<"\n Tenants record successfully added

..........................................";
}
void EditRecord() //function to edit records of an existing tenant.
{ clrscr();
tenant T33;
ifstream fin;
ofstream fout;
char id[10],po;
int f=0;
cout<<"\n";
cout<<"ENTER RECORD ID TO EDIT >> ";
gets(id);
fin.open("Tenant.dat",ios::binary|ios::in); //To open file.
if(!fin)
{cout<<"Sorry!! the file does not exists";

}
fout.open("Modiftenant.dat",ios::binary|ios::out|ios::app);

//To open file.


fin.read((char*)&T33,sizeof(T33)); //To read data

from file.
while(!fin.eof())
{
if(strcmp(T33.checkID(),id)==0)
{
cout<<" ********* ENTER NEW

DATA FOR THIS RECORD ***************";


cout<<"\n";
cout<<"-----------------------------------

-----------------------------------------";
cout<<"\n Tenant ID whose record is to

be changed ...... -> "<<id<<"\n";


strcpy(T33.TenantID,T33.checkID());
T33.modif();
fout.write((char*)&T33,sizeof(T33));

//To write data on the file.


cout<<"

-----------------------------------------";
cout<<"\n Record has been updated

sucessfully.....";
f=1;
}
else
{ fout.write((char*)&T33,sizeof(T33));

//To write data on the file.


}
fin.read((char*)&T33,sizeof(T33)); //To

read data from file.


}
fin.close();
fout.close();
remove("Tenant.dat"); //To delete the file.
rename("Modiftenant.dat","Tenant.dat"); //To rename the file.
if (f==0)
{
cout<<"\n";
cout<<" Reached End-of-Datafile...";
cout<<endl<<endl;
cout<<" NO SUCH RECORD EXISTS...";
}
cout<<"\nDo you wish to view the rent list(y/n) ";
cin>>po;
if(po=='y'||po=='Y')
{ ViewReport();} //Function call.
}
void DelRecord() //function to delete records of a tenant.
{ clrscr();
tenant T4;
ifstream file;
ofstream buf;
char id[10],po;
int f=0;
long pos;
cout<<"\n";
cout<<" ENTER RECORD-ID TO DELETE ............>> ";
gets(id);
buf.open("Deletenant.dat",ios::binary|ios::out|ios::app); //To

open the file.


file.open("Tenant.dat",ios::binary|ios::in); //To open the

file.
if(!file) //To search till the file ends.
{cout<<"Sorry!! the file does not exists";
}
file.read((char*)&T4,sizeof(T4)); //To read data from the file.
while(!file.eof())
{
if(strcmp(T4.checkID(),id)==0)
{ f=1;
}
else
{
buf.write((char*)&T4,sizeof(T4)); //To

write data on the file.


}
file.read((char*)&T4,sizeof(T4)); //To read

data from the file.


}
buf.close();
remove("Tenant.dat"); //To delete the file.
rename("Deletenant.dat","Tenant.dat"); //To

rename the file.


cout<<"\n Record deleted sucessfully................";
file.close(); //To close the file.
if (f==0)
{
cout<<"\n";
cout<<" Reached End-of-Datafile...";
cout<<endl<<endl;
cout<<" NO SUCH RECORD EXISTS...";
}
cout<<"\nDo you wish to view the rent list(y/n) ";
cin>>po;
if(po=='y'||po=='Y')
{ ViewReport(); //Function call.
}
}
void AdjRent() //function to adjust rent of a tenant.
{ clrscr();
tenant T5;
ofstream fout;
ifstream fin;
char id[10],se;
int f=0;
cout<<"\n";
cout<<"ENTER RECORD-ID TO ADJUST RENT........>>";
gets(id);
fout.open("Rent.dat",ios::binary|ios::out); //To open the file.
fin.open("Tenant.dat",ios::binary|ios::in); //To close the file.
if(!fin)
{cout<<"Sorry!! the file does not exists";

}
fin.read((char*)&T5,sizeof(T5)); //To read data from the

file.
while(!fin.eof()) //To search till the file ends.
{
if(strcmp(T5.checkID(),id)==0)
{
int amt;
cout<<"\nCurrent Rent ->"<<"

"<<T5.DueAmount;
cout<<"\n\nEnter adjustment amount

->";
cin>>amt;
cout<<"\nThe adjustment amount

should be: "


<<"\n1)ADDED"
<<"\n2)DEDUCTED";
lb3:
cout<<"\nEnter your choice (1/2) ->> ";
cin>>se;
if(se=='1')
{
T5.DueAmount=T5.DueAmount+amt;
fout.write((char*)&T5,sizeof(T5));

//To write data on the file.


cout<<"\n\nRent updated

sucessfully.....";
f=1;
}
else if(se=='2')
{
T5.DueAmount=T5.DueAmount-amt;
fout.write((char*)&T5,sizeof(T5));
//To write data on the file.
cout<<"\n\nRent updated

sucessfully.....";
f=1;
}
else
{cout<<"\nWrong choice entered.......";
goto lb3;
}
}
else
{ fout.write((char*)&T5,sizeof(T5)); //To write

data on the file.


} //To read data from the file.
fin.read((char*)&T5,sizeof(T5));
}
fout.close(); //To close the file.
fin.close(); //To close the file.
remove("Tenant.dat"); //To delete the file.
rename("Rent.dat","Tenant.dat"); //To rename the file.
if (f==0)
{
cout<<"\n";
cout<<" Reached End-of-Datafile...";
cout<<endl<<endl;
cout<<" NO SUCH RECORD EXISTS...";
}
}
void ViewSpcRecord() //function to view records of a tenant.
{ clrscr();
tenant T2;
ifstream file;
char id[10];
int f=0;
cout<<"\n";
cout<<"\n ENTER RECORD ID TO VIEW

DETAILS.............>>";
gets(id);
file.open("Tenant.dat",ios::binary|ios::app); //To open the

file.
if(!file)
{cout<<"Sorry!! the file does not exists";
}
while(!file.eof()) //To search till the end of the

file.
{
file.read((char*)&T2,sizeof(T2));
if(strcmp(T2.checkID(),id)==0)
{ T2.putdata();
cout<<endl;
f=1;
break;
}
}
file.close(); //To close the file.
if (f==0)
{
cout<<"\n";
cout<<" Reached End-of-Datafile...";
cout<<endl<<endl;
cout<<" NO SUCH RECORD EXISTS...";
}
}
void ViewReport() //function to display rent paid (ID wise).
{ clrscr();
tenant T1;
ifstream file;
file.open("Tenant.dat",ios::binary|ios::in); //To open the file.
cout<<"\n\t\t";
cout<<" ************TENANT-ID WISE DUE RENT

REPORT ************ ";


cout<<endl;

cout<<"\n---------------------------------------------------------------------";
cout<<endl;
cout<<" TENANT-ID|\t TENANT NAME|\t FATHER NAME|

\t RENT PAID";
cout<<endl;
cout<<"-----------|\t------------|\t-------------|\t---------------";
file.read((char*)&T1,sizeof(T1)); //To read data from the

file.
while(!file.eof()) //To search till the end of the
file.

{
if(file.eof())
break;
T1.PrintSumary();
file.read((char*)&T1,sizeof(T1)); //To read data

from the file.


}

cout<<"\n-------------------------------------------------------------------";
cout<<"\n Reached End-of-Datafile...................................";
file.close(); //To close the file.
}
void IncomeReport() //function to show income of the society from

maintanance and rent.


{ clrscr();
tenant T21;
long t=0,s=0;
int m,n;
char l[10];
ifstream file;
file.open("Tenant.dat",ios::binary|ios::in); //To open the file.
cout<<"\n\t\t";
cout<<" ***********INCOME REPORT ************ ";
cout<<"\n\n TENANT- ID\t\tMAINTENANCE(Rs.)\tRENT

(Rs.)";
cout<<endl;
cout<<"-----------|\t\t-------------- | -------------\n";
file.read((char*)&T21,sizeof(T21)); //To read data from

the file.
while(!file.eof()) //To search till the end of the file.
{
strcpy(l,T21.checkID());
m=T21.Rent();
n=T21.DueAmount;
t+=m;
s+=n;
cout<<l<<"\t\t\t"<<m<<"\t\t\t"<<n<<endl;
file.read((char*)&T21,sizeof(T21)); //To read
data from the file.
}
cout<<"\n---------------------------------------------------";
cout<<"\nTotal Income from Maintenance ="<<t;
cout<<"\nTotal Income from Rent ="<<s;
file.close(); //To close the file.
}
void BlockReport() //function to see report of a renant block

wise.
{ clrscr();
tenant T11;
char bg;
ifstream file;
file.open("Tenant.dat",ios::binary|ios::in); //To open the file.
cout<<"\nEnter Block name whose report is to be viewed :";
cin>>bg;
cout<<"\n\t\t";
cout<<" *********BLOCK- WISE DUE MAINTENANCE

REPORT ************ ";


cout<<"\nBLOCK|\t TENANT- ID|\t TENANT NAME|\t
FLAT|\t MAINTENANCE";
cout<<endl;
cout<<"------|\t-----------|\t ------------|\t --------|\t ------------";
file.read((char*)&T11,sizeof(T11)); //To read data from the

file.
while(!file.eof()) //To search till the end of the file.
{
if(T11.Bock()==bg)
T11.PrintSummary();
file.read((char*)&T11,sizeof(T11)); //To read

data from the file.


}
cout<<"\n------------------------------------------------------------";
cout<<"\n Reached End-of-Datafile.........................................";
file.close(); //To close the file.
}
void Flat() //function to display information about flats and families of

the society.
{ char g;
clrscr();
cout<<"\n----------------------------FLATS AND

FAMILIES----------------------------------\n"
<<"\nThe Society is divided in 3 Blocks A,B and

C.All the block have around 30-35\n"


<<"\nflats in them.Total number of flats in the

society are 98.Some of the flats have \n"


<<"\nbeen purchased and some of the flats are on

rent. All the flats are 3 BHK. Some \n"


<<"\npeople occupy 2 rooms and some other tenant

occupies 1 room.All the people \n"


<<"\nliving are very Cooperative and helpful and

celebrate every festival with \n"


<<"\nhappiness irrespective of what their religion

is.. \n"
<<"\n*Press 1->GO BACK\t\t\t*Press any key-

>TO TERMINATE\n";
cin>>g;
if(g=='1')
{About();} //Function call.
}
void Facilities() //function to display facilities provided by the society.
{ char g;
clrscr();
cout<<"\n--------------------------OTHER

FACILITIES------------------------------------\n"
<<"\nThe Society has a swimming pool in the

centre of the society for enjoyment\n"


<<"\nof children.There is a temple near the C block

where people can go and pray\n"


<<"\nand worship god.Apart from this there is a

society club near the temple \n"


<<"\nwhere functions and society gatherings are

held on occasions of Diwali, Holi\n"


<<"\nand New year where families enjoy and get

releived from stress.\n"


<<"\n*Press 1->GO BACK\t\t\t*Press any key-

>TO TERMINATE\n";
cin>>g;
if(g=='1')
{About();} //Function call.
}
void Contact() //function to display contact information of members of

society parliament.
{ char p;
clrscr();
cout<<"\n\t****************CONTACT

US**************************"
<<"\nMr.Madan Khatri"
<<"\nSociety President"
<<"\n9832167865"
<<"\[email protected]"
<<"\nFlat: C-14 "
<<"\n\nMr.Bitto Kumar"
<<"\nSociety Vice President "
<<"\n9721867865"
<<"\[email protected]"
<<"\nFlat: A-11"
<<"\n\nMr.Abhijeet Das"
<<"\nSociety Secretary"
<<"\n9832167865"
<<"\[email protected]"
<<"\nFlat: B-18"
<<"\n\nSociety E-mail"
<<"\[email protected]"
<<"\nTelephone-01123346578"
<<"\n\t\t\t\tPress any key----------------> ";
p=getche(); //To accept a character.
}
void Parks() //function to display information about the parks in the

society.
{ char g;
clrscr();
cout<<"\n--------------------------

PARKS-----------------------------------------\n"
<<"\nThe Society has 3 parks in total, one near the
entrance, one near the B block\n"
<<"\nand one near the Temple.One of the parks is

meant for the purpose of outdoor\n"


<<"\n gameslike football having two goalposts

inside it .Rest of the two parks are \n"


<<"\nmeant for people of all ages.The parks are full

of trees and flowers which makes\n"


<<"\nyou feel fresh There are swings as well in the

park for people with small \n"


<<"\nchildren\n\n*Press 1->GO BACK\t\t\t*Press

any key->TO TERMINATE\n";


cin>>g;
if(g=='1')
{About();} //Function call.
}
void Security() //function to display security servicies provided by the

society.
{ char g;
clrscr();
cout<<"\n-------------------------SECURITY

SERVICES-----------------------------------\n"
<<"\nThe Society has high security services for the

safety of people and property.\n"


<<"\nThere are 4 security guards in total, 2 of them

having duty in day and two of\n"


<<"\nthem having duty at night.A barricater is

provided at the main gate to allow\n"


<<"\nonly society cars and bikes to enter.Apart

from this CCTV cameras are \n"


<<"\ninstalled at almost every corner of the society

whose monitor is at main \n"


<<"\nenterance in security room.\n"
<<"\n\n*Press 1->GO BACK\t\t\t*Press any key-

>TO TERMINATE\n";
cin>>g;
if(g=='1')
{About();} //Function call.
}
void About() //function to show the menu "About the society".
{ clrscr();
int q;
cout<<"\n***********************About the

society**************************"
<<"\n1..FLATS AND FAMILIES"
<<"\n2..PARKS"
<<"\n3..SECURITY"
<<"\n4..OTHER FACILITIES"
<<"\n5..BACK TO MAIN MENU"
<<"\nEnter your choice(1-5)...>> ";
cin>>q;
switch(q)
{
case 1: Flat(); //Function call.
break;
case 2: Parks(); //Function call.
break;
case 3: Security(); //Function call.
break;
case 4: Facilities(); //Function call.
break;
case 5: break;
default: cout<<"Sorry!!! wrong choice

entered ";
About();
}
}
void main() //main function starts.
{ char k;char ch,pk,h;
clrscr(); // Menu to select colors.
cout<<"\n************************Welcome To Heavens

Gate Society*********************\n";
A:
int t;
cout<<"\nEnter color code (1-6)\n1.Dark Blue\n2.Green

\n3.Sky Blue\n4.Red\n5.Pink\n6.Orange\n\n ------>>";


cin>>t;
if((t<=7)&&(t>=1))
{
textcolor(t); //Code for adding colour to the text.
cprintf(" ");
}
else
{ cout<<"\nWrong choice, please enter again!";
goto A; }
system ("pause");
clrscr();

do { clrscr(); // Main menu.

cout<<"\n ********************** MAIN MENU

**********************";

cout<<"\n---------------------------------------------";

cout <<"\n <1> A NEW TENANT IN THE SOCIETY ??"

<<"\n <2> ENQUIRY ABOUT A TENANT ??"

<<"\n <3> EDIT AN EXISTING RECORD ??"

<<"\n <4> ANY TENANT LEFT THE SOCIETY ??"

<<"\n <5> ANY DUE RENT TO ADJUST ??"

<<"\n <6> VIEW DUE RENT REPORT ??"


<<"\n <7> ANNUAL INCOME FROM RENT ??"

<<"\n <8> VIEW REPORT BLOCK WISE(A/B/C ) ??"

<<"\n <9> KNOW ABOUT THE SOCIETY ??"

<<"\n <0> CONTACT US ??"

<<"\n <#> EXIT THE SOCIETY ??"<<endl;

cout<<"---------------------------------------------";

cout<<"\n Your Choice Goes Here >> ";

k=getche(); //To accept a character.

switch(k) //Initiating switch case.

case '1': AddRecord(); //Function

call.

break;

case '2': ViewSpcRecord(); //Function

call.

break;
case '3': EditRecord(); //Function call.

break;

case '4': DelRecord(); //Function call.

break;

case '5': AdjRent(); //Function call.

break;

case '6': ViewReport(); //Function

call.

break;

case '7': IncomeReport(); //Function

call.

break;

case '8': BlockReport(); //Function

call.

break;

case '9': About(); //Function call.


break;

case '0': Contact(); //Function call.

break;

case '#':cout<<"\n You Have Chosen

Exit....";

cout<<"\n Press any character to

exit this window...";

ch=getche(); //To accept a

character.

exit(-1);

default: cout<<"\n \n

Oops!!!.......INVALID SELECTION";

cout<<" \n TRY AGAIN";

cout<<"\nDo you want to continue(y/n)"; //To run


the program for as long as the user wants.

cin>>h;

if((h=='N')||(h=='n'))

{ cout<<"do you want to go to the main menu?

(Y/y)\n";

cin>>pk;

if((pk=='Y')||(pk=='y'))

goto A;

else exit(-1);

}while((h=='y')||(h=='Y'));

getch();

} //main function ends.

//Program ends

You might also like