Sep 29, 2014

Customer Biling System[Package Code]

1:14 AM Posted by Unknown , No comments
  Reference code:http://www.codewithc.com/customer-billing-system-project-in-c/ 
  
  if you need the package source code,Please see the end of article.

Source Code:

//Author   : LearningPen
//Date     : 2014/9/29
//Language : C++
//Tool     : Dev C++
//MyBlog   :http://learningpen.blogspot.com/

#include <iostream>
#include <windows.h>
#include <conio.h>
#include <string>

using namespace std;

void Input( void );
void WriteFile( void );
void Search( void );
void Output( void );
void gotoxy( int x, int y );
void textcolor( int color );
void Menu( void );

struct date
{
int month;
int day;
int year;
};

struct account
{
int   number;
char  name[ 100 ];
int   acct_no;  //account number
float mobile_no;
char  street[ 100 ];
char  city[ 100 ];
char  acct_type;
float oldbalance;
float newbalance;
float payment;
struct date lastpayment;
}customer; 


int main( void )
{
int choice;
//int num= 0;

system( "cls" );
textcolor( 14 );

Menu();

gotoxy( 24, 12 );
cout<< "Enter your choice(0- 2): ";
cin>> choice;


switch( choice )
{
case 1:
{

   Input();

if( customer.payment > 0 )
{
customer.acct_type= ( customer.payment< 
 0.1* customer.oldbalance ) ? 'O' : 'D';
}
else
{
customer.acct_type= ( customer.oldbalance> 0) ?
'D' : 'C';
}

customer.newbalance= customer.oldbalance- customer.payment;

WriteFile();

main();  //goto main()...
}
case 2:
{
Search();

main();  //goto main().........
}
case 0:
{
gotoxy( 24, 16 );
textcolor( 12 );
cout<< "Thank you for using.";
gotoxy( 24, 17 );
cout<< "Welcome to My Blog:http://learningpen.blogspot.com/";
textcolor( 14 );

Sleep( 1000 );  //wait a second

exit( 1 );
}
}

return 0;
}

//------------------function ------
void gotoxy( int x, int y )
{
COORD pos= { 0, 0 };
HANDLE handle= GetStdHandle( STD_OUTPUT_HANDLE );

pos.X= x;
pos.Y= y;

SetConsoleCursorPosition( handle, pos );

return ;
}

void textcolor( int color )
{
HANDLE handle= GetStdHandle( STD_OUTPUT_HANDLE );

SetConsoleTextAttribute( handle, color );

return ;
}

void Menu( void )
{
gotoxy( 18, 4 );
cout<< "★☆☆CUSTOMER BILLING SYSTEM☆☆★";

gotoxy( 18, 5 );
cout<< "-----------------------------------";

gotoxy( 24, 7 );
cout<< "1.) Add account on list ";

gotoxy( 24, 8 );
cout<< "2.) Search customer account ";

gotoxy( 24, 9 );
cout<< "0.) Exit ";

gotoxy( 18, 11 );
cout<< "-----------------------------------";

return ;
}

void Input( void )
{
int SizeLength, TotalSize, TotalLength;

FILE *fp= fopen( "Bill.dat", "rb" );
if( NULL== fp )
{
system( "cls" );

cout<< "Cannot open file!!";

exit( 1 );
}

fseek( fp, 0, SEEK_END );
SizeLength= ftell( fp );
TotalLength= sizeof( customer );
TotalSize= SizeLength/ TotalLength;

fseek( fp, ( TotalSize- 1)* SizeLength, SEEK_END );
fread( &customer, sizeof( customer ), 1, fp );

system( "cls" );
gotoxy( 18, 3 );
cout<< "★☆☆CUSTOMER BILLING SYSTEM☆☆★";
gotoxy( 24, 4 );
cout<< "Appending........";

gotoxy( 20, 7 );
customer.number++;
textcolor( 12 );
cout<< "Customer No: "<< customer.number;
textcolor( 14 );

gotoxy( 24, 9 );
cout<< "Account number: ";
textcolor( 12 );
cin>> customer.acct_no;
textcolor( 14 );

gotoxy( 24, 10 );
cout<< "Name: ";
textcolor( 12 );
cin>> customer.name;
textcolor( 14 );

gotoxy( 24, 11 );
cout<< "Mobile No: ";
textcolor( 12 );
    cin>> customer.mobile_no;
    textcolor( 14 );
    
    gotoxy( 24, 12 );
    cout<< "Street: ";
    textcolor( 12 );
    cin>> customer.street ;
    textcolor( 14 );
    
    gotoxy( 24, 13 );
    cout<< "City: ";
    textcolor( 12 );
    cin>>customer.city;
    textcolor( 14 );
    
    gotoxy( 24, 14 );
    cout<< "Precvious balance: ";
    textcolor( 12 );
    cin>> customer.oldbalance;
    textcolor( 14 );
    
    gotoxy( 24, 15 );
    cout<< "Current payment: ";
    textcolor( 12 );
    cin>> customer.payment;
    textcolor( 14 );
    
    gotoxy( 24, 16 );
    cout<< "Payment date( dd mm yy ): ";
    textcolor( 12 );
    cin>> customer.lastpayment.day>> customer.lastpayment.month>> customer.lastpayment.year;
    textcolor( 14 );
    
    return ;    
}


void WriteFile( void )
{
FILE *fp;

fp= fopen( "Bill.dat", "ab" );
fwrite( &customer, sizeof( customer ), 1, fp );

fclose( fp );

return ;

}


void Search( void )
{
FILE *fp;
int TotalSize, TotalLength, SizeLength;
int choice;
int num;
char name[ 100 ];
int n;
int flag= 0;

fp= fopen( "Bill.dat", "rb" );
if( NULL== fp )
{
system( "cls" );
textcolor( 14 );
gotoxy( 24, 11 );

exit( 1 );
}


system( "cls" );
gotoxy( 18, 2 );
cout<< "★☆☆CUSTOMER BILLING SYSTEM☆☆★";

gotoxy( 24, 4 );
cout<< "1.) Search by customer numuber ";

gotoxy( 24, 5 );
cout<< "2.) Search by customer name ";

gotoxy( 24, 7 );
cout<< "Enter your choice(1/ 2): ";
cin>>choice;

gotoxy( 24, 9 );
    cout<< "Searching...........";

switch( choice )
{
case 1:
{
fseek( fp, 0, SEEK_END );
TotalLength= ftell( fp );
SizeLength= sizeof( customer );

TotalLength= TotalLength/ SizeLength;

gotoxy( 24, 11 );
cout<< "Enter customer number: ";
cin>> num;

if( num<= 0 && num> TotalSize )
{
gotoxy( 24, 13 );
cout<< "Please,Enter correct!!!";
}
else
{
fseek( fp, ( num- 1 )* SizeLength, SEEK_SET );
fread( &customer, SizeLength, 1, fp );

Output();  // printing
}

break;
}
case 2:
{
fseek( fp, 0, SEEK_END );
TotalLength= ftell( fp );
SizeLength= sizeof( customer );

TotalSize= TotalLength/ SizeLength;

fseek( fp, ( TotalSize- 1 )* SizeLength, SEEK_SET );
fread( &customer, sizeof( customer), 1, fp );

n= customer.number;

gotoxy( 24, 11 );
cout<< "Enter the name: ";
textcolor( 12 );
cin>> name;
textcolor( 14 );

fseek( fp, 0, SEEK_SET );

for( int i= 0; i<= n; i++ )
{
fread( &customer, sizeof( customer), 1, fp );
if( strcmp( customer.name, name )== 0 )
{
Output();    // If found, the print
flag= 1;

break; 
}
}

if( flag== 0 )
{
gotoxy( 24, 13 );
textcolor( 14 );
cout<< "Not Found!!";
textcolor( 12 );

gotoxy( 24, 15 );
cout<< "Press any key to continue.";
}
}

   fclose( fp );
}

getch();

return ;
}

void Output( void )
{
system( "cls" );
gotoxy( 15, 2 );
cout<< "★☆☆CUSTOMER BILLING SYSTEM☆☆★";
textcolor( 14 );

gotoxy( 18, 4 );
cout<< "Showing...........";

gotoxy( 18, 6 );
textcolor( 12 );
cout<< "Customer No: ";
cout<< customer.number;
textcolor( 14 );

gotoxy( 24, 7 );
cout<< "Name:";
textcolor( 12 );
cout<< customer.name;
textcolor( 14 );

gotoxy( 24, 8 );
cout<< "Mobile No: ";
textcolor( 12 );
cout<< customer.mobile_no;
textcolor( 14 );

gotoxy( 24, 9 );
cout<< "Account number: ";
textcolor( 12 );
cout<< customer.acct_no;
textcolor( 14 );

gotoxy( 24, 10 );
cout<< "Street: ";
textcolor( 12 );
cout<< customer.street;
textcolor( 14 );

gotoxy( 24, 11 );
cout<<"City: ";
textcolor( 12 );
cout<< customer.city;
textcolor( 14 );

gotoxy( 24, 12 );
cout<< "Old balance: ";
textcolor( 12 );
cout<< customer.oldbalance ;
textcolor( 14 );

gotoxy( 24, 13 );
cout<< "Current Payment: ";
textcolor( 12 );
cout<< customer.payment;
textcolor( 14 );

gotoxy( 24, 14 );
cout<< "New balance: ";
textcolor( 12 );
cout<< customer.newbalance;
textcolor( 14 );

gotoxy( 24, 15 );
cout<< "Payment date: ";
textcolor( 12 );
cout<< customer.lastpayment.year
    << "/"<< customer.lastpayment.month<< "/"<<customer.lastpayment.day; 
textcolor( 14 );

gotoxy( 24, 16 );
cout<< "Account status: ";
textcolor( 12 );
switch( customer.acct_type )
{
case 'C':
{
cout<< "CURRENT";

   break;
}
case 'O':
{
cout<< "OVERDUE";

break;
}
case 'D':
{
cout<< "DELINQUENT";

break;
}
default:
{
cout<< "ERROR";

break;
}

}
textcolor( 14 );

gotoxy( 24, 20 );
cout<< "Press any key continue.";

getch();

return ;

}

Package Source link:Here
ScreenShot:








0 Comment:

Post a Comment