Sei sulla pagina 1di 40

INDEX

1. BONAFIDE CERTIFICATE
2. ACKNOWLEDGEMENT
3. AN OVERVIEW OF C++
4. SYSTEM REQUIREMENTS
5. INTODUCTION
6. PROGRAM ANALYSIS
7. SOURCE CODE
8. OUTPUT
9. LIMITATIONS AND FUTURE
ENHANCEMENTS
10. BIBLIOGRAPHY
ACKNOWLEDGEMENT

I would like to thank our beloved Correspondent


Mrs.Jeyalekshmy, for permitting me to carry out this
project in Devi Academy Senior Secondary School.

I would also like to acknowledge the timely help extended


by Mrs. Uma Maheshwari, Principal.

I am greatly indebted to my respected teacher Mrs.


Maheshwari Balu, Mrs. Srimathi.V without whom this
project would never have taken form.
OVERVIEW OF C++
The C++ programming language was developed at AT&T
Bell Laboratories in the early 1980’s by Bjarne Stroustrup.
He found ‘C’ lacking for simulations and decided to extend
the language by adding features to his favourite language,
Simula 67.
Simula 67 was one of the earliest object-oriented
languages. Bjarne Stroustrup called it “C with classes”
originally. The name C++ was coined by Rick Mascitti
where “++” is the C increment operator. Ever since its
birth, C++ has evolved to cope with problems
encountered by users through discussions at AT&T.
However, the maturation of the C++ language was
attested by two events:
(i) The formation of ANSI (American National Standard
Institute C++ Committee.
(ii) The publication of the annotated C++ Reference
Manual by Ellis and Stroustrup.

The latest C++ standards document was issued by ANSI


ISO in the year 2003.
The major reason behind the success and popularity of
C++ is that it supports the object oriented technology, the
latest in the software development and the near to real
world.

One can easily judge the importance of C++ has by the


given following lines:
"OBJECT ORIENTED TECHNOLOGY IS REGARDED AS
THE ULTIMATE PARADIGM FOR THE MODELING OF
INORMATION BE IT DATA OR LOGIC. THE C++ HAS BY
NOW SHOWN TO FULFILL GOALS."
Object is an identifiable entity with some characteristics
and behaviour.
The OOP approach is based on certain concepts that help
in attain its goal by overcoming the drawbacks or
shortcomings of conventional programming approaches.

The general OOP concepts are given below:


1. Data abstraction
2. Data encapsulation
3. Modularity
4. Inheritance (Hierarchy)
5. Polymorphism

OOP TERMINOLOGY AND FEATURES

1. Encapsulation
The wrapping up 0 data and functions (that operate
on the data into single unit (called class) is known as
Encapsulation.

2. Data Abstraction
Abstraction refers to the act of representing
essential features without including the background detail
or explanations.

3. Modularity
Modularity is the property of a system that has been
decomposed into set of cohesive and coupled modules.

4. Inheritance
Inheritance is the capability 0 one class 0 things to
inherit capabilities or properties from another class.

5. Polymorphism
Polymorphism is the ability for a message or data to
be processed in more than one form. Polymorphism is a
property by which the same message can be sent to
objects of several different classes.

1. int data_type( for integers)


2. char data_type(for characters)
3. float data_type( or floating point values)
4. double data_type( or double precision floating point
numbers)
5. void data_type (for empty set of values and non-
returning functions)

Stream Description
cin Console input
cout Console output
cerr Standard error
clog Buffered version of error

1. const int rate=50;


2. const float p=3.0;
3. const char ch=’a';

roll=27;
The symbol '=' is an assignment operator. The
significance of the above statement is that 'roll' is a
symbolic name for memory locations where the value i27
is being stored. The character';' is the statement
terminator. It marks the end of the C++ statement.

Keywords
A keyword is a reserved word of C++. This cannot be
used as an identifier by the user in his program.
Examples of some valid keywords are:
1. class
2. private
3. return
4. while

Constants
A symbolic name or identifier which does not change its
value during exception of a program is known as
constant. Constant qualifier can be used to declare
constant as shown below
const float p=3.5

Variables
A variable is an identifier. It is the most fundamental
aspect of any computer language. It is a location in the
computer memory which can store data and is given a
symbolic name for easy reference.
I/O STATEMENTS

The following C++ streams can be used for the input


output purpose:

Operators
An operator is a symbol or letter used to indicate a
specific operation on variable in a program. For eg '+' is
an addition operator that adds two data items called
operands.

Flow of control
The architecture of a general purpose computer is von-
Neumann architecture.
Such a computer use serial sequential nature. Therefore
the normal flow of execution of statements in a high level
language is also sequential, i.e. each statement is
executed in the order of its appearance in the program.

The following are the available control statements in C++ :


1. if
2. if ... else
3. switch case

Repetitive statements
Some problems require the set of statements should be
executed more than one time, each time changing one or
more variables, so that every execution is different from
the previous one. This kind of repetitive execution of a set
of statements in a program is known as iteration loop.
1. while loop,
2. do while loop and
3. for loop
are the iterative statements.

Arrays
An array is a structure with the help of which a
programmer can refer to and perform operations on a
group of similar data items such as simple lists or tables
of information. An array whose elements are specified by
a single subscript is known as single dimensional array.
The array whose elements are specified by two or more
subscripts is known as multi-dimensional array.

Strings
A string is a group of characters of any length. A string
is enclosed within quotation marks as literal. For e.g.
"Hello" is a literal. The strings can be stored and
manipulated as array of characters. The last character is
always '\0' a null character with ASCII value equal to
0.thus, the effective size of an array is one more than the
size of string it can hold
C o M P u T E R '\0'

Two dimensional Arrays


A two dimensional array of characters is known as an
array of strings. The row subscripts decide as to how
many strings can be stored in the array and the column
subscript tells the size of each string.
For e.g. char d[20][10];

Functions
A subprogram of function is a name given to a set of
instructions that can be called by another program or a
subprogram.
A function is a complete program in itself in the sense that
its structure is similar to C++ main function except that the
name is replaced by the name of the function, the general
form of a function given below:
<type><name>(arguments)

Function prototypes
Similar to variables, all functions must be declared
before they are used in a program. C++ allows the
declaration of functions in the calling program with the
help of a function prototype in the calling program is given
below:
<type><name>( arguments)

Parameter passing function


The two way of communication between the various
function can be achieved through parameter and return
statement. The set of parameters defined in a function are
called actual parameters.
The functions that have parameters can be called in one
of the following two ways
1. Call by value
2. Call by reference
Functions
Functions are building blocks of the programs. They
make the programs more modular and easy to read and
manage. All C++ programs must contain the function
main(). The execution of the program starts from the
function main(). A C++ program can contain any number
of functions according to the needs.

The general form of the function is:


return_type function _ name(parameter list);
{
Body of the function
}

The function consists of two parts:


1. Function header
2. Function body.

The function header


returntype function_name(parameter list);
The return type specifies the type of data the function
returns. The return _ type can be void which means
function does not return any data type. The
function_name is the name of the function, the name of the
function should begin with alphabet or underscore. The
parameter list consists of variables separated with
comma along with their data types the parameter list
should contain both type and name of the variable.
For example:
int factorial (int n,float j);
Is the function header of function factorial, the return type
is of integer which means function should return data of
type integer. The parameter list contains two variables n
and j of type integer and float respectively. The body of
the function performs the computations.

Function Declaration
Function declaration is made by declaring the return
type of the function, e of the function and the data type of
the parameters of the function. A function declaration is
same as the declaration of the variable. The function
declaration is always terminated by the semicolon. A call
to the function cannot be made unless it is declared.
The general form of the declaration is:
return_typefunction_name (parameter list);
For example:
int factorial (int n, float j);
The variables name need not be same as the variables in
the parameter list of the function.
Another method can be

int factorial (int, float);

The variables in the function declaration can be optional


but the data types are necessary.

Function arguments
The information is transferred to the function by the
means of the arguments when a call to a function is made.
Arguments contain the actual value which is to be passed
to the function when it is called.
The sequence of the arguments in the call of a function
should be same as the sequence of the parameters in the
parameter list of the declaration of the function.
The data types of the arguments should correspond with
the data types of the parameters. When a function call is
made arguments replace the parameters of the function.

Return statement and Returning Values


A return statement is used to exit from the function where
it is. It returns the execution of the program to the point
where the function call was made. It returns a value to the
calling code. The general form of the return statement is:
return expression;

The return expression evaluates a value which has the


type same as the return type specified in the function
declaration.
For example, the statement:
return(n); is the return statement of the factorial
function. The type of variable n should be a integer as
specified in the declaration of the factorial function. If a
function has return type as void then return statement
does not contain any expression. It is written as
return;
The function with return type as void can ignore the return
statement. The closing braces at the end indicate the exit
of the function.

Here is a program which illustrates the working of the


functions:

#include<iostream.h>
using name space std;
int factorial (int n);
int main()
{
int n, fact;
cout«"enter the number whose factorial is to be
calculated"«endl;
cin>>n;
fact=factorial(int n);
cout«"the factorial of'«n«"is"«endl;
return(0);
}

int factorial (int n)


{
inti=0;
fact= 1;
If(n<=l)
{
return(i);
}
else
{
for(inti=0;i<=n;i++)
{
fact=fact*i;
}
return (fact);
}
}

The function factorial calculates the factorial of the


number entered by the user. If the number is less than or
equal to I then the function returns 1 else it returns the
factorial if the number.

The statement:
int factorial (int n);
is a declaration of the function. The return type is integer.
The statements:
cout«"Enter the number whose factorial has to be
calculated"«endl;
cin»n;
make the user enter the number, whose factorial is to be
calculated. The variable n stores the number entered by
the user. The user has entered number 5.
The statement:
fact=factorial(nl );
makes a call to the function containing two return
statements. If the value entered by the user is less than
and equal to I then the value I is returned else computed
factorial is returned.
The type of the expression returned is integer.

Parameter passing mechanism


There are two parameters passing mechanism for
passing the arguments to functions such as
1. pass by value method
2.pass by reference method.

Pass by value
In ‘pass by value’ mechanism copies of the argument are
created and which are stored in the temporary locations
of the memory. The parameters are mapped to the copies
of the arguments created. ‘Pass by value’ mechanism
provides security to the calling program.

Here is a program which illustrates the working of pass by


value mechanism:

#include<iostream.h>
using namespace std;
int add (int n);
int main()
{
lnt number, result;
number=5;
cout«"the initial value of the number"«number«endl;
result=add( number);
cout«" the final value of the number"«number«endl;
cout«"the result is"«result«endl;
return(o);
}

int add(int number)


{
number =number + 100;
return(number);
}
The value of the variable before calling function is 5.
The function call is made and the function adds 100 to the
parameter number. When the function is returned the
result contains the added value. The final value of the
number remains same as 5. This program shows that
operation on parameters do not produce the effect on the
argument.

Pass by reference
Pass by reference is the second way of passing
parameters to the function. The address of the argument
is copied into the parameter. The changes made to the
parameter affect the arguments. The address of the
argument is passed to the function and function modifies
the values of the arguments in the calling function.

Here is the program which illustrates the working of pass


by reference mechanism:

#include <iostream.h>
name space std;
int add {int& number);
int main()
{
int number;
int result;
number=5;
cout«" the value of the variable number before
calling the function" <<number<<endl;
result=add(& number);
cout«"the value of the variable after the function is
returned is"«number«endl;
cout«"the value of result"«result«endl;
return(0);
}
int add(int&p)
{
*p=*p+ 1000;
return(&p);
}

The address of the variable is passed to the function. The


variable p points the memory address of the variable
number. The value is incremented by 100. It hangs the
actual contents of the variable number. The value of
variable number before calling the function is 100 and
after function is returned the value of variable is changed
to 105.

FSTREAM HEADER FILE


The C++ input/output operations are very much similar to
the console input and output operations. The file
operations also make use of streams as an interface
between programs and files.
A stream is a sequence of bytes.
A stream is general name given to flow of data. Different
streams are used to represent different kinds of data flow.
Each stream is associated with a particular kind of data
flow.

ifstream
Being an input file stream class, it provides input
operation for a file. It inherits the function get(), getline(),
read() and functions supporting random access from
ifstream class defined inside fstream.h.
ofstream
Being an output file stream class, it provides onput
operation for a file. It inherits the function put(), putline(),
write() and functions supporting random access from
ofstream class defined inside fstream.h.
fstream
It is an input/output stream class, it provides support for
simultaneous input/output operations.
Minimum System
Requirements
 Intel 1.5 GHz Pentium 1 Processor
 VGA Card
 14’’ CRT Monitor
 16 MB RAM
 20 GB Available HDD Space
 104-Key Keyboard
Program Definition
To write a C++ program to develop a MOBILE STORE
BILLING SYSTEM using file handling.

Program Analysis

Required header files

fstream.h – for file handling functions such as read() and


write().
conio.h – for console input/output functions such as
getch() and clrscr().
process.h – for exit() function.
stdio.h – for remove() and rename() functions to delete
and rename files, and gets() to accept strings.
string.h – for strcmpi() function to compare strings.

Classes used:

class mobile – a class to accept details of mobiles and to


display the details of the product.
Functions used:

void writemobile() – function to write into file.


void display_all – function to read all records from file.
void display_sm(char *ch) – function to read specific
records.
void modifymobile() – function to modify record.
void deletemobile() – function to delete record from file.
void place_order() – function to place order and
generating bills for
products.
void intro() – introduction function.
void admin_menu() – administrator menu function.
void main() – main function of program.
Program Coding
Mobile Store Billing System

#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<string.h>

class mobile
{char mname[50], brand[50];
float price, dis;
int qty;
public:

void createmobile()
{cout<<"Enter mobile name:";
gets(mname);
cout<<"Enter brand name:";
gets(brand);
cout<<"Enter price:";
cin>>price;
cout<<"Enter quantity:";
cin>>qty;
cout<<"Enter discount:";
cin>>dis;
}

void showmobile()
{ cout<<"\nMOBILE
NAME\tBRAND\tPRICE\tQTY\tDISCOUNT\n"<<mname;
cout<<"\t\t"<<brand;
cout<<"\t"<<price;
cout<<"\t"<<qty;
cout<<"\t"<<dis;
}

float retprice()
{return price;}

int retqty()
{return qty;}
char * retbrand()
{return brand;}

float retdiscount()
{return dis;}

char * retmname()
{return mname;}

void writemobile();
void readmobile();
void modifymobile();
void deletemobile();
};
fstream fio;
mobile m;
void mobile::writemobile()
{ fio.open("shop.dat",ios::out|ios::app);
m.createmobile();
fio.write ((char *) &m, sizeof(mobile));
fio.close();
cout<<"\nThe mobile has been created";
getch();
}

void display_all()
{clrscr();
cout<<"\t\tDISPLAY ALL
RECORDS\n____________________________________________
____";
fio.open("shop.dat",ios::in);
while(fio.read((char *)&m, sizeof(mobile)))
{m.showmobile();
cout<<"\n
\n________________________________________________";
}
fio.close();
getch();
}

void display_sm(char *ch)


{int flag=0;
fio.open("shop.dat", ios::in);
while(fio.read((char* )&m, sizeof(mobile)))
{if(strcmpi(m.retmname(),ch)==0)
{
m.showmobile();
flag=1;
getch();
}
}
fio.close();
if(flag==0)
cout<<"record does not exist";
}

void mobile::modifymobile()
{char ch[50];
int found=0;
clrscr();
cout<<"\n TO MODIFY";
cout<<"\n Enter mobile name:";
gets(ch);
fio.open("shop.dat", ios::in|ios::out);
while(fio.read((char* )&m,sizeof(mobile)) && found==0)
{
if(strcmpi(m.retmname(),ch)==0)
{m.showmobile();
cout<<"\nEnter details of mobile\n";
m.createmobile();
int pos=-1 * sizeof(mobile);
fio.seekp(pos, ios::cur);
fio.write((char *)&m, sizeof(mobile));
cout<<"Record updated";
found=1;
}
}
fio.close();
if(found==0)
cout<<"Record not found";
getch();
}

void mobile::deletemobile()
{char ch[50];
clrscr();
cout<<"\n DELETE RECORD";
cout<<"\n \n Please enter the mobile name you wish to
delete:";
gets(ch);
fio.open("shop.dat",ios::in|ios::out);
fstream fio2;
fio2.open("temp.dat",ios::out);
fio.seekg(0, ios::beg);
while(fio.read((char *)&m,sizeof(mobile)))
{
if(strcmpi(m.retmname(),ch)!=0)
{fio2.write((char *)&m, sizeof(mobile));
}
}
fio.close();
fio2.close();
remove("shop.dat");
rename("temp.dat", "shop.dat");
cout<<"\n \n Record deleted";
getch();
}
void menu()
{clrscr();
fio.open("shop.dat",ios::in);
if(!fio)
{ cout<<"error! file could not be opened \n go to admin
menu to create file";
cout<<"\n \n program is closing";
getch();
exit(0);
}
cout<<"\n \n MOBILE MENU \n\n";
cout<<"_________________________________________\n";
cout<<"BRAND \t\tMOBILE NAME\tPRICE\n";
cout<<"_________________________________________\n";
while(fio.read((char *)&m, sizeof(mobile)))
{
cout<<m.retbrand()<<"\t\t"<<m.retmname()<<"\t\t"<<m.ret
price()<<"\n";
}
fio.close();
}
void place_order()
{ int quan[50],c=0;
char order_arr[50][50];
float amt,damt,total=0;
char ch='y';
menu();
cout<<"\n _____________________________";
cout<<"\n Place your order";
cout<<"\n _____________________________";
do
{
cout<<"\n Enter the name of the mobile: ";
gets(order_arr[c]);
cout<<"Enter the quantity: ";
cin>>quan[c];
c++;
cout<<"\n Do you want to order another mobile(y/n) ?";
cin>>ch;
}while(ch=='Y'||ch=='y');
cout<<"\n \n Thank you for placing the order";
getch();
clrscr();
cout<<"\n
\n*************************INVOICE***************************
**\n";
cout<<"\n BRAND \t NAME\t\tQTY\tPRICE\tAMT\tAMT
AFTER DISCOUNT \n";
for(int x=0; x<c; x++)
{
fio.open("shop.dat", ios::in);
fio.read((char *)&m, sizeof(mobile));
while(!fio.eof())
{if(strcmpi(m.retmname(),order_arr[x])==0)
{amt=m.retprice()*quan[x];
damt=amt-(amt*m.retdiscount()/100);
cout<<"\n"<<m.retbrand()<<"\t"<<order_arr[x]<<"\t\t"<<qu
an[x]<<"\t"<<m.retprice()<<"\t"<<amt<<"\t"<<damt;
total+=damt;
}
fio.read((char *)&m, sizeof(mobile));
}
fio.close();
}
cout<<"\n\n\t\t TOTAL= "<<total;
}
void intro()
{ clrscr();
gotoxy(31,11);
cout<<" MOBILE STORE";
gotoxy(35,14);
cout<<"BILLING";
gotoxy(26,17);
cout<<"PROJECT";
cout<<" MADE BY:NISHA K";
cout<<"\n\n\t\t SCHOOL: DEVI ACADEMY SR.
SECONDARY SCHOOL";
getch();
}
//administration menu fn
void admin_menu()
{clrscr();
char ch2;
cout<<"\n\n\n ADMIN MENU";
cout<<"\n\n\t 1.CREATE MOBILE";
cout<<"\n\n\t 2.DISPLAY ALL MOBILES";
cout<<"\n\n\t 3.QUERY";
cout<<"\n\n\t 4.MODIFY MOBILE";
cout<<"\n\n\t 5.DELETE MOBILE";
cout<<"\n\n\t 6.VIEW MAIN MENU";
cout<<"\n\nPLEASE ENTER YOUR CHOICE(1-6)";
cin>>ch2;
switch(ch2)
{
case '1': clrscr();
m.writemobile();
break;
case '2': display_all();
break;
case '3': char n[50];
clrscr();
cout<<"\n\t Please enter the mobile name:";
gets(n);
display_sm(n);
break;
case '4':m.modifymobile();
break;
case '5':m.deletemobile();
break;
case '6':menu();
break;
default: cout<<"\a";
admin_menu();
}
}

void main()
{char ch;
intro();
do
{clrscr();
cout<<"\n\n\t MAIN MENU";
cout<<"\n\n\t a.CUSTOMER";
cout<<"\n\n\t b.ADMINISTRATOR";
cout<<"\n\n\t c.EXIT";
cout<<"\n\n\t Please enter your choice(a-c)";
cin>>ch;
switch(ch)
{
case 'a': clrscr();
place_order();
getch();
break;
case 'b':admin_menu();
break;
case 'c': exit(0);
default: cout<<"\a";
}
}while(ch!='c');
}
INPUT AND OUTPUT
MAIN MENU

ADMIN MENU
CREAT MOBILE

DISPLAY ALL RECORDS


DISPLAY DETAILS OF SPECIFIC MOBILE

MODIFYING MOBILE
DELETE RECORD

PLACING ORDER
INVOICE
Result

A C++ program on mobile store billing system that


involves creation of bills, addition and deletion of
products, using discounts where the data is stored in a
binary file is successfully created and executed.

Limitations and Future


Enhancements

This project can be made use of in all mobile stores and


helps in increasing the efficiency of service which helps in
developing a greater sense of satisfaction in the
customers.

Bibliography

 Computer Science with C++ by Sumita Arora


 C++ by Balagurusamy

Potrebbero piacerti anche