Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
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
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.
Stream Description
cin Console input
cout Console output
cerr Standard error
clog Buffered version of error
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
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.
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'
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)
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
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.
#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);
}
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.
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.
#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);
}
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.
#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);
}
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
Classes used:
#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 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
MODIFYING MOBILE
DELETE RECORD
PLACING ORDER
INVOICE
Result
Bibliography