Thursday 8 October 2015

Mini Project in C Telecom Billing System

Features of Telecom Billing System in C:

Simple functions have been used in co-ordination with data structure and file handling. As the project is relatively short, you can thoroughly go through the whole source code; this will help you understand data structure and file handling if you know their fundamentals. You’ll also get the basic idea regarding “how to develop a C mini project” in a very simple manner.
The functions and features used in this project are listed below:
  • Add new records: add new data into file with name, phone number and amount to be paid
  • View list of records – lists all telephone billing records (as shown in screenshot 3)
  • Modify records – edit the added records; name, phone number and/or amount of payment can be edited
  • View payment – shows amount to be paid
  • Search records – search for added/updated records in file
  • Delete records – removes data permanently from file
This project is limited to the functions aforementioned. You can add new features as you like to make this project a better one.
CODE:
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
#include<windows.h>
#include<stdlib.h>
struct subscriber
{
char phonenumber[20];
char name[50];
float amount;
}s;
void addrecords();
void listrecords();
void modifyrecords();
void deleterecords();
void searchrecords();
void payment();
char get;
int main()
{ int password;
int phonenumber;
char choice;



system("cls");

printf("\n\n\n\n\n\n\n\n\n**************************************************************");
printf("\n\t\t------WELCOME TO THE TELECOM BILLING MANAGEMENT SYSTEM---");
printf("\n\t\t****************************************************************");
Sleep(2000);
getch();
    system("cls");
while (1)
{
system("cls");
printf("\n Enter\n A : for adding new records.\n L : for list of records");
printf("\n M : for modifying records.\n P : for payment");
printf("\n S : for searching records.");
printf("\n D : for deleting records.\n E : for exit\n");
choice=getche();
choice=toupper(choice);
switch(choice)
{
case 'P':
payment();break;
case 'A':
addrecords();break;
case 'L':
listrecords();break;
case 'M':
modifyrecords();break;
case 'S':
searchrecords();break;
case 'D':
deleterecords();break;
case 'E':
system("cls");
printf("\n\n\t\t\t\tTHANK YOU");
printf("\n\n\n\n\n:\n\tFOR USING OUR SERVICE");
Sleep(2000);
exit(0);
break;
default:
system("cls");
printf("Incorrect Input");
printf("\nAny key to continue");
getch();
}
}
}
void addrecords()
{
FILE *f;
char test;
f=fopen("c:/file.ojs","ab+");
if(f==0)
{   f=fopen("c:/file.ojs","wb+");
system("cls");
printf("please wait while we configure your computer");
printf("/npress any key to continue");
getch();
}
while(1)
{
system("cls");
printf("\n Enter phone number:");
scanf("%s",&s.phonenumber);
printf("\n Enter name:");
fflush(stdin);
scanf("%[^\n]",&s.name);
printf("\n Enter amount:");
scanf("%f",&s.amount);
fwrite(&s,sizeof(s),1,f);
fflush(stdin);
system("cls");
printf("1 record successfully added");
printf("\n Press esc key to exit, any other key to add other record:");
test=getche();
if(test==27)
break;
}
fclose(f);
}
void listrecords()
{
FILE *f;
int i;
if((f=fopen("c:/file.ojs","rb"))==NULL)
exit(0);
system("cls");
printf("Phone Number\t\tUser Name\t\t\tAmount\n");
for(i=0;i<79;i++)
printf("-");
while(fread(&s,sizeof(s),1,f)==1)
{
printf("\n%-10s\t\t%-20s\t\tRs. %.2f /-",s.phonenumber,s.name,s.amount);
}
printf("\n");
for(i=0;i<79;i++)
printf("-");

fclose(f);
getch();
}
void deleterecords()
{
FILE *f,*t;
int i=1;
char phonenumber[20];
if((t=fopen("c:/temp.ojs","w+"))==NULL)
exit(0);
if((f=fopen("c:/file.ojs","rb"))==NULL)
exit(0);
system("cls");
printf("Enter the phone number to be deleted from the Database");
fflush(stdin);
scanf("%[^\n]",phonenumber);
while(fread(&s,sizeof(s),1,f)==1)
{
if(strcmp(s.phonenumber,phonenumber)==0)
{       i=0;
continue;

}
else
fwrite(&s,sizeof(s),1,t);
}
if(i==1)
{       system("cls");
printf("Phone number \"%s\" not found",phonenumber);
remove("c:/file.ojs");
rename("c:/temp.ojs","c:/file.ojs");
getch();
fclose(f);
fclose(t);
main();
}
remove("c:/file.ojs");
rename("c:/temp.ojs","c:/file.ojs");
system("cls");
printf("The Number %s Successfully Deleted!!!!",phonenumber);
fclose(f);
fclose(t);
getch();
}
void searchrecords()
{
FILE *f;
char phonenumber[20];
int flag=1;
f=fopen("c:/file.ojs","rb+");
if(f==0)
exit(0);
fflush(stdin);
system("cls");
printf("Enter Phone Number to search in our database");
scanf("%s", phonenumber);
while(fread(&s,sizeof(s),1,f)==1)
{
if(strcmp(s.phonenumber,phonenumber)==0)
{ system("cls");
printf(" Record Found ");
printf("\n\nPhonenumber: %s\nName: %s\nAmount: Rs.%0.2f\n",s.phonenumber,s.name,s.amount);
flag=0;
break;
}
else if(flag==1)
{ system("cls");
printf("Requested Phone Number Not found in our database");
}
}
getch();
fclose(f);
}
void modifyrecords()
{
FILE *f;
char phonenumber[20];
long int size=sizeof(s);
if((f=fopen("c:/file.ojs","rb+"))==NULL)
exit(0);
system("cls");
printf("Enter phone number of the subscriber to modify:");
scanf("%[^\n]",phonenumber);
fflush(stdin);
while(fread(&s,sizeof(s),1,f)==1)
{
if(strcmp(s.phonenumber,phonenumber)==0)
{
system("cls");
printf("\n Enter phone number:");
scanf("%s",&s.phonenumber);
printf("\n Enter name: ");
fflush(stdin);
scanf("%[^\n]",&s.name);
printf("\n Enter amount: ");
scanf("%f",&s.amount);
fseek(f,-size,SEEK_CUR);
fwrite(&s,sizeof(s),1,f);
break;
}
}
fclose(f);
}
void payment()
{
FILE *f;
char phonenumber[20];
long int size=sizeof(s);
float amt;
int i;
if((f=fopen("c:/file.ojs","rb+"))==NULL)
exit(0);
system("cls");
printf("Enter phone number of the subscriber for payment");
scanf("%[^\n]",phonenumber);
fflush(stdin);
while(fread(&s,sizeof(s),1,f)==1)
{
if(strcmp(s.phonenumber,phonenumber)==0)
{
system("cls");
printf("\n Phone No.: %s",s.phonenumber);
printf("\n Name: %s",s.name);
printf("\n Current amount: %f",s.amount);
printf("\n");
for(i=0;i<79;i++)
printf("-");
printf("\n\nEnter amount of payment :");
fflush(stdin);
scanf(" %f",&amt);
s.amount=s.amount-amt;
fseek(f,-size,SEEK_CUR);
fwrite(&s,sizeof(s),1,f);
break;
}
}
system("cls");
printf("THANK YOU %s FOR YOUR TIMELY PAYMENTS",s.name);
getch();
fclose(f);
}

3 comments:

  1. can any one help me for this
    The following data is some information about Mr Ahmad credit card. The data is store in a file, name mycard.txt.
    VISA cimb 2011
    VISA maybank 2010
    Masters rakyat 2015
    Amex islam 2010
    Dinners public 2009
     Help Mr Ahmad to develop a program that can store and retrieve the information about his credit card.
     Declare a structure to store the information with structure name cardinfo.
     The data member of the structure is cardname, bankname and expiry.
     Initialize card1 to take the data members of the structure cardinfo.
     Open and read the input in the data file.
     Check either the input file is in the same directory as the code or not.
     Initialize the input to card1

    ReplyDelete
  2. can any one help me for this
    The following data is some information about Mr Ahmad credit card. The data is store in a file, name mycard.txt.
    VISA cimb 2011
    VISA maybank 2010
    Masters rakyat 2015
    Amex islam 2010
    Dinners public 2009
     Help Mr Ahmad to develop a program that can store and retrieve the information about his credit card.
     Declare a structure to store the information with structure name cardinfo.
     The data member of the structure is cardname, bankname and expiry.
     Initialize card1 to take the data members of the structure cardinfo.
     Open and read the input in the data file.
     Check either the input file is in the same directory as the code or not.
     Initialize the input to card1

    ReplyDelete
  3. Thanks for writing this great article! It’s very informative, and you included some great points to the equally great article regarding Telecom Billing System.

    ReplyDelete