This is a program on Telephone Billing. There's only one error and it says- "Identifier 'append' cannot have a type qualifier.
Code:
//**********************************************************************************
// PROJECT TELEPHONE-BILLING
//**********************************************************************************
// TELEPHONE BILLING
//Header files
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<process.h>
#include<ctype.h>
#include<dos.h>
#include<dir.h>
#include<fstream.h>
//Class having the record of customer
class customer
{ char ph[10];
char name[30];
char add[40];
char type;
public:
[B][I]void append();[/I][/B]
void display();
void deleter();
void modify();
void list();
void help();
} cust;
//Function to display the message at the bottom of the screen
void message (char mess[80])
{
int l, d;
l = strlen(mess);
d=l/2;
gotoxy(2,24);
textcolor(WHITE+BLINK);
textbackground(BLACK);
cprintf(" ");
gotoxy(40-d, 24);
clreol();
cprintf("%s", mess);
textcolor(BLACK);
textbackground(WHITE);
}
//Main function having the main menu
void main()
{
textcolor(BLACK);
textbackground(WHITE);
char ch, ch1;
while(1)
{
clrscr();
textcolor(BLACK);
textbackground(WHITE);
gotoxy(25,5);
cprintf("MAHANAGAR TELEPHONE NIGAM LTD.");
textcolor(BLACK);
textbackground(WHITE);
gotoxy(25,8);
cout<<" D - Display a Bill";
gotoxy(25,10);
cout<<"L - List of Customers";
gotoxy(25,12);
cout<<"H - Help";
gotoxy(25,14);
cout<<"M - Modify a Record";
gotoxy(25,16);
cout<<"Q - Quit";
message("Select your Choice");
gotoxy(40,18);
ch=getch();
ch=toupper(ch);
switch(ch)
{
case('Q') : textcolor(WHITE);
textbackground(BLACK);
clrscr();
exit(1);
case('D') : cust.display();
break;
case('L') : cust.list();
break;
case('H') : cust.help();
break;
case('M'):
ch1 = 'A';
while(ch1 != 'Q' )
{
clrscr();
textcolor(WHITE);
textbackground(BLACK);
gotoxy(25,5);
cprintf("MAHANAGAR TELEPHONE NIGAM LTD.");
textcolor(BLACK);
textbackground(WHITE);
gotoxy(25,9);
cout<<"A - Append a record";
gotoxy(25,11);
cout<<"D - Delete a record";
gotoxy(25,13);
cout<<"M - Change a record";
gotoxy(25,15);
cout<<"Q - Quit";
message("Select your option");
ch1 = getch();
ch1 = toupper(ch1);
switch(ch1)
{
case('A') : cust.append();
break;
case('D') : cust.deleter();
break;
case('M') : cust.modify();
break;
}
}
}
}
}
//Function to add the customer record in the file
[B][I]void customer :: append()
{
char choice;
fstream fp;
fp.open("tphone.dat", ios::app);
if (!fp)
{
cout<<"Unable to open FILE.";
getch();
return;
}
while(1)
{
clrscr();
gotoxy (3,3);
cout<<"Customer Record #";
message("Enter the customer record");
while(1)
{
message("Enter the name");
gotoxy(3,5);
cout<<"Name : ";
gotoxy(25,5);
gets(name);
if(strlen (name) == 0)
{
gotoxy(2,23);
clreol();
textcolor(WHITE+BLINK);
textbackground(BLACK);
}
else
break;
}
while(1)
{
gotoxy(3,7);
cout<<"Assigned Ph. No. : ";
gotoxy(25,7);
cin>>ph;
if (ph != 0 )
break;
else
{
gotoxy(25,7);
clreol();
}
}
message ("Enter O for Office and R for Residential phone");
gotoxy (3,8);
cout<<"Category (O/R) : ";
cin>>type;
gotoxy(4,10);
cout<<"1 : Save & Exit 2 : Save & Cont. 0 : Exit without save";
gotoxy(4,11);
cout<<"? ";
cin>>choice;
switch(choice)
{
case ('1') : fp.write ( (char *) this, sizeof (cust) );
fp.close();
return;
case ('2') : fp.write( (char *) this, sizeof (cust) );
break;
case ('0') : fp.close();
return;
default : fp.close();
return;
}
}
} [/I][/B]
//Function to display the customer record and calculate the bill
void customer :: display()
{
char p[10];
char choice;
int found=0;
int no;
float bill=0.0, tax=0.0, fine=0.0, bbill=0.0, abill=0.0;
fstream fp;
fp.open("tphone.dat", ios::in);
if (!fp)
{
cout<<"Unable to open a file";
getch();
fp.close();
return;
}
while (choice != '0' )
{
clrscr ();
gotoxy(3,20);
cout<<"Please enter the Phone No. ";
cin>>p;
if (!strcmp(p,"0"))
return;
found = 0;
fp.seekg(0);
while (fp.read ( (char *) this, sizeof (cust) ) )
{
if (founf==1)
break;
if(!strcmp (ph,p) )
{
clrscr();
gotoxy(28,2);
textcolor(BLACK+BLINK) ;
textbackground(WHITE);
cprintf("MAHANAGAR TELEPHONE BILL");
textcolor(WHITE);
textbackground(BLACK);
gotoxy(3,4);
cout<<"Name : ";
cout<<name;
gotoxy(35,5);
cout<<"Address : ";
cout<<add;
gotoxy(35,4);
cout<<"Assigned Ph. No. : ";
cout<<ph;
gotoxy(3,5);
cout<<"Category ( O/R ) : ";
cout<<type;
gotoxy(23,8);
cout<<"_____________";
gotoxy(10,8);
cout<<"No. of calls ";
cin>>no;
if ( no <= 150 )
bill = 0;
else
{
no = no - 150;
if ( toupper (type) == 'O')
bill = np * 1.00 ;
else
bill = no * .80;
}
gotoxy (10,9);
cout<<"Bill";
gotoxy (70,9);
cout<<bill;
tax = (5*bill) / 100;
gotoxy (10,10) ;
cout<<"5 % Tax ";
gotoxy (70,10);
cout<<tax;
gotoxy (10,11);
cout<<"Duties";
gotoxy (70,11);
cout<<"100";
int dd, mm, yy;
struct date d; //Getting system date
getdate (&d);
dd = d.da_day;
mm = d.da_mon;
yy = d.da_year;
gotoxy (10,15);
cout<<"TOTAL BILL before ";
cout<<dd<<"/"<<mm<<"/"<<yy;
bbill = bill+tax+100;
gotoxy (70,15);
cout<<bbill;
gotoxy (10,17);
cout<<"Late Fine";
fine = (bbill*5) / 100;
gotoxy (70,17);
cout<<fine;
gotoxy (10,21);
cout<<"TOTAL BILL after ";
cout<<dd<<"/"<<mm<<"/"<<yy;
abill = bbill + fine;
gotoxy (70,21);
cout<<abill;
found = 1;
message ("Press a Key");
getch();
}
}
message ("Enter 1 or 2 to cont.");
gotoxy (4,22);
cout<<"1 : Cont. 0 : Exit ";
cout<<"? ";
cin>>choice;
switch(choice)
{
case ('1') :
break;
case ('0') : return;
default : return;
}
}
fp.close();
}
//Function to display the list of the customers
void customer :: list()
{
clrscr();
fstream fp;
int r;
fp.open ("tphone.dat"; ios::in);
if ( !fp )
{
cout<<"Unable to open";
getch();
fp.close();
return;
}
gotoxy (35,2);
cout<<"List of customers";
gotoxy (35,3);
cout<<"**************";
gotoxy (5,4);
cout<<"Name";
gotoxy (40,4);
cout<<"Phone No.";
gotoxy (65,4);
cout<<"Category";
gotoxy (1,5);
cout<<"***********************************************************************************************";
r=6;
while ( fp.read (char *) this, sizeof (cust) ) )
{
if (r >= 21)
{
message ("Press a key");
getch();
clrscr();
gotoxy (35,2);
cout<<"List of customers";
gotoxy (35,3);
cout<<"**************";
gotoxy (5,4);
cout<<"Name";
gotoxy (40,4);
cout<<"Phone No.";
gotoxy (65,4);
cout<<"Category";
gotoxy (1,5);
cout<<"***********************************************************************************************";
r=6;
}
gotoxy (5,r);
cout<<name;
gotoxy (40,r);
cout<<ph;
gotoxy (65,r);
if (toupper (cust.type) == 'O' )
cout<<"Office";
else
cout<<"Residential";
r++;
}
message ("Press a key");
getch();
fp.close();
}
//Function to delete the record of customer from the file
void customer :: deleter()
{
char ch;
char p[10];
fstream temp, fp;
fp.open ("tphone.dat", ios::in);
if ( !fp )
{
cout<<"Unable to open Telephone file";
getch();
fp.close();
return;
}
temp.open ("temp.dat", ios::out);
if (!temp)
{
cout<<"Unable to open Temporary file";
getch();
temo.close();
return;
}
clrscr();
gotoxy (5,3);
cout<<"Enter the Phone No. to be deleted : ";
cin>>p;
if( !strcmp (p,"0") )
return;
int found = 0;
while (fp.read ( (char *) this, sizeof(cust) ) )
{
if ( !strcmp(p,ph) )
{
found = 1;
gotoxy (5,5);
cout<<"Name "<<name;
gotoxy (5,6);
cout<<"Address "<<add;
gotoxy (5,7);
cout<<"Category "<<type;
gotoxy (6,10);
cout<<"Delete this record (Y/N) ";
cin>>ch;
if ( toupper(ch) == 'N' )
temp.write ((char*) this, sizeof (cust) );
}
else
temp.write ((char*) this, sizeof (cust));
}
fp.close();
temp.close();
if (toupper(ch) == 'N')
return;
if (!found)
{
cout<<"\n\nTelephone no. not found";
getch();
return;
}
fp.open ("tphone.dat", ios::out);
temp.open("temp.dat", ios::in);
while (temp.read ((char*) this, sizeof(cust) ) )
fp.write ((char*) this, sizeof (cust) );
fp.close();
temp.close();
}
//Function to modify the record of customer from the file
void customer :: modify()
{
char ch;
char p[10];
fstream temp, fp;
fp.open ("tphone.dat", ios::in);
if (!fp)
{
cout<<"Unable to open Telephone file";
getch();
fp.close();
return;
}
temp.open ("temp.dat", ios::out);
if (!temp)
{
cout<<"Unable to open Temporary file";
getch();
temp.close();
return;
}
clrscr();
gotoxy (5,3);
cout<<"Enter the Phone No. to be modify : ";
cin>>p;
if( !strcmp(p,"0") )
return;
int found=0;
while (fp.read ((char*) this, sizeof (cust) ) )
{
if (!strcmp (p,ph) )
{
found = 1;
gotoxy (5,5);
cout<<"Name "<<name;
gotoxy (5,6);
cout<<"Address "<<add;
gotoxy (5,7);
cout<<"Category "<<type;
gotoxy (6,10);
cout<<"Modify this record (Y/N) ";
cin>>ch;
if ( toupper(ch) == 'Y' )
{
gotoxy (3,13);
cout<<"Customer Record #";
message ("Enter the customer record");
while(1)
{
gotoxy (3,15);
cout<<"Name : ";
gets(name);
if (strlen (name) != 0)
break;
}
gotoxy (3,16);
cout<<"Address : ";
gets (add);
while (1)
{
gotoxy (3,17);
cout<<"Assigned Ph. No. : ";
cin>>ph;
if (ph != 0)
break;
}
message("Enter O for Office and R for Residentil phone");
gotoxy (3,18);
cout<<"category (O/R) : ";
cin>>type;
}
}
temp.write( (char*) this, sizeof (cust) );
}
fp.close();
temp.close();
if (toupper(ch) == 'N')
return;
if (!found)
{
cout<<"\n\nTelephone no. not found";
getch();
return;
}
fp.open ("tphone.dat", ios::out);
temp.open ("temp.dat", ios::in);
while ( temp.read ((char*) this, sizeof (cust) ) )
fp.write ((char *) this, sizeof (cust) );
fp.close();
temp.close();
}
//Function to display the discription for the project working
void customer :: help()
{
clrscr();
gotoxy (35,2);
textcolor (WHITE + BLINK);
textbackground (BLACK);
cprintf ("HELP");
textcolor (BLACK);
textbackground (WHITE);
gotoxy (8,5);
cout<<"Thsi software is used to create a telephone bill for the customers.";
gotoxy (8,7);
cout<<"There are two categories of the customers. First categories is of";
gotoxy (8,9);
cout<<"Resedential phones and second categories is of Office phones. Both";
gotoxy (8,11);
cout<<"the categories have different charges of the telephone bill. Charges";
gotoxy (8,13);
cout<<"of resedential phones are 80 paose per call and charges of office";
gotoxy (8,15);
cout<<"office phones are Rs. 1 per call. 150 call are free for each category";
gotoxy (8,17);
cout<<"Total bill is equal to 5% tax plus 100 rupees charges for other";
gotoxy (8,19);
cout<<"charges. If bill is not paid before the paticular date then penalty";
gotoxy (8,21);
cout<<"should also be given.";
getch();
};
}
Comment