You are on page 1of 65

A

PRACTICAL TRAINING REPORT


ON

Project Student Management

AT

APTECH COMPUTER CENTRE, Abohar

Submitted for the partial fulfillment for the award of Diploma


of Engineering (Electronics & Communication)

Submitted to: Submitted by:


Mrs. RANJIT KAUR Mani shankar
Coordinator 2nd Year (3rd Semester)
electronics & communication

DEPARTMENT OF ELECTRONICS AND COMMUNICATION


SANT LONGOWAL INSTITUTE OF ENGINEERING &
TECHNOLOGY, LONGOWAL
ACKNOWLEDGEMENT
This Training has been done with tedious efforts and consistent
dedication. I hope this training will be appreciated. Now it time to
thank all the people who helped me directly or indirectly to
achieve my goal. The people who always keep on guiding me like
sign boards and did never expect anything from me. But after the
completion of this project, I would like to pay my sincere thanks
to all who apparently or non-apparently helped me in developing
this project and surely deserve it.
No work can be perfect without the ample guidance. I
would like to express my deep gratitude and heartiest thanks to
our Director Dr.(Mrs) S.K.Panday and the Training and
Placement Officer who infused us with the spirit to work upon
challenging field, which has its inception such a time when there
is a need for new orientation.
I'm thankful to the CENTER MANAGER of APTECH
Computer Mr. Baljinder Phutela for showing trust in me and
providing me chance to work in his company. Also I'm thankful to
the Mr. Kamal Suresh (Technical Instructor) who helped
me, guided me and provided me various valuable suggestions
which will be always helpful for me.

MANI SHANKAR
II Year DIPLOMA (III Semester)
ELECTRONICS & COMMUNICATION
PREFACE
Practical training is an important part of the engineering. During
practical training, we learn how work is actually done, in the real
sense. Beside this we also learn code of conduct as well as how
to behave in the working environment. After getting training we
get accustom to the working environment. These things are
important part and we learn to apply them in our professional
life.
In today information computer are being used in every
occupation. They are being used by the people of all age and
profession in there work, As well as in there leisure. This new
social revolution has change the basic concept of computing.
Computing, in today’s information age is no more limited to
computer programmers and computer engineer it has become
and activity of common man. so one should know how to
program a computer.
CONTENTS

PREFACE
ACKNOWLEDGEMENT

INTRODUCTION 1
STEPS IN RUNNING A C++ PROGRAM 3
DISADVANTAGES 4
CONSTANT,VARIABLES AND DATA TYPES 5
OPERATORS ANDEXPRESSIONS 8
DATA I/P AND O/P 10
CONTROL FLOW STATEMENTS 11
FUNCTIONS 16
ARRAY 19
STRUCTURE 20
UNION 20
OOPS 21
CHARACTERISTICS OF LOOPS 24
CONSTRUCTORS AND DESTRUCTORS 25
FRIEND FUNCTIONS 26
OPERATOR OVERLOADING 26
INHERITANCE 28
FILE HANDLING 35
APPLICATIONS 39
COADING OF PROJECT 40
Introduction to programming languages(C++)

A program is a set of instructions which tells a computer about


which data to be input and which to output.
Many different languages are used to program a computer. The
most basic of these languages is machine language, which is a
collection of instructions that controls the computer’s internal
circuitry. However, very few computer programs are actually
written in machine language for two reasons:
1. Machine language is very difficult to work with.
2. Most computers have their own unique instruction sets – so a
machine language program written for one type of computer
cannot be run on another type of computer without being
changed.

Usually a computer program is written in a high-level language for


two reasons:
1. Instructions of high-level language matches with human
languages.
2. The same general programming rules apply to all computers – so
a program written in a high-level language can generally be run
on many different with a little or no alteration.
A program written in high-level language must, however, be
translated into machine language before it can be executed. The
original high-level language program is called the source program
and the resulting machine-language program is called object
program, while the process of translation is known as compilation
or interpretation depending on how it is carried out.
1. Compilers translate the entire program into machine language
before executing any of the instructions.
2. Interpreters proceed through a program by translating and then
executing single instructions.
Steps in running a c/c++ program
Executing a program involves following steps:
1. Creating the program:-
The first step includes simply typing in the program in any text
editor like edit, notepad or VI editor. The program file must
however be saved with the extension ‘.c’. Thus a C program file is
always saved as “filename.c”.
2. Compiling the program:-
It involves translating the source code to the object code. This step
is implemented differently in different operating steps.
3. Linking the program:-
It is the process of putting together other program files and
functions that are required by the program.
e.g. sqrt() function, the object code of this function should be
brought from the math library and linked to the main() program.

To compile the program welcome.cpp in MSDOS, we must type


MSC welcome.cpp.
On doing so, the object code is stored in a file named welcome.obj.
The linking is done by command
LINK welcome.obj
Which generates the executable code in a file named welcome.exe.
Finally to execute the program welcome.c, we have to simply type
the following at the command prompt. Welcome
Advantages of ‘C/C++’:
1. Machine independence: There codes can be compiled on
different machines and they produce the same output when
executed.
2. Economy of expression: They are compact and coherent
programming languages. The codes are very powerful so that a
small length of codes can perform complex tasks.
3. Data structures: There are several ways to store data on C/C+
+, which allows easy access of data.
4. Operator richness: They support a wide range of operators to
handle arithmetic and logical calculations.

Disadvantages of ‘C/C++’:

1. Difficult to debug: They give a lot of freedom to the developer,


but it is a bit difficult for any new user to find out where is the
error in the program.
2. Loosely syntaxed: They allow a lot of freedom in coding. We
can give end of statement symbols (;), blank lines, white spaces
anywhere we want in the program. There is no fixed place to
start or end a line. This can give rise to codes that are difficult to
understand by reading.
Constants, Variables and Data types

C++ character set


Following are the valid alphabets, numbers and special symbols
allowed in c:
Alphabets A, B, C……………, Y, Z
a, b, c……………., y, z
Digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Special symbols ~! @ # % ^ & * ( ) _ - +
|\{}[]:;‘ <>, .?/=

C++ keywords

The words whose meaning has already been explained to the c


compiler are called keywords.
There are 32 keywords in C.C++ has all these but some extra also.
They appear in white color on programming screen.
Few important keywords are:
Auto, double, int, float, struct, class etc.

Data types
The important data types used in C++ are:
Char:
It holds individual characters and occupies 1 byte.

Int:
It requires 2 bytes and range of storage is -32767 to +32768, it
stores only the whole integer numbers.

Float:
It can hold decimal numbers also; it takes 4 bytes.It can give up to
6 digits after decimal.

Double:
It also stores the decimal values but it can give up to 15 digits after
decimal. It requires 8 bytes.

We can also add some modifiers in front of these data types so that
we can alter their range according to our need. Important modifiers
are short, long, signed, unsigned.

Constants
Like identifiers or variables we can have constants of the type int,
float, and char.
Integer constants:
They are simply the integer valued numbers. They are sequence of
digits taken between 0 and 9. Zero cannot be the starting digit.
They have a positive or a negative sign in their front. They can be
represented as decimal, octal and hexadecimal.
Floating point constant:
A floating point constant is a decimal number that contains either
decimal or an exponent form. It is a sequence of digits having a
decimal in between. It can also have a positive or a negative sign in
front. Its general exponential form is: mantissa E exponent.
Character constant:
It is simply a single character. It is always defined inside single
quotation (‘a’). We can also write ‘4’ but it is different from 4
because in this case ‘4’ is represented by it’s ASCII(American
standard code for information interchange) value which is different
for every character being used in c.
String constant:
A string is simply a sequence of characters. It is represented by
putting double quotation (“welcome”). The compiler puts a null
(‘\0’) character at the end of every string.

Symbolic constants (macros):


If we have to use a value 3.142 (value of constant pi) many times
then it will be very time consuming to write and also understanding
about for what purpose the value is written, for this we can use
macros and define them in the beginning of the program.
e.g. we can write #define pi 3.142
Now we can directly write pi at all places where we have written
3.142. In this way we can improve readability of the code and also
easy maintenance of the code.
Declaration of variables:
Syntax: data-type var1, var2, var3… varn;
Where data-type tells the compiler about whether it is a character,
integer, or a decimal number. e.g. int n; float interest; char x;

Operators and Expressions


An operator is a symbol that tells the compiler to perform certain
mathematical and logical operations. The data items that operators
act upon are called as “operands”. The operators which need one
operand at a time are called unary operators whereas those using
two operands are called binary operators.
C operators can be classified as:
1. Arithmetic operators.
2. Relational operators.
3. Logical operators.
4. Assignment operators.
5. Conditional operators.
6. Special operators.
C++ has all these operators but also some extra operators. These
are:
1. Stream input/output operators(<<,>>)
2. scope Resolution operators(::)
3. line feed operators(endl)
4. field width operators(setw)
5. memory allocation operators(new)
6. memory deallocation operators(delete)

The chart below shows the operators with the order of precedence:
Operator’s name Operators’
1. Unary operator - ++ -- !
2. Arithmetic multiply */%
divide, modulus
3. Arithmetic add, + -
Subtract
4. Relational operator <= < > >=
5. Equality operators == !=
6. Logical and &&
7. Logical OR ||
8. Conditional operator ?:
9. Assignment operator = += -= *= /= %=

Special operators are sizeof operator, pointer operators (& and *)


and member selection operators (. and ->).
Data input and output

While writing the program we need input/output functions cout or


cin, for calling these functions we have to include some header files
like stdio.h and iostream.h which are given in two ways:
#include<stdio.h> this tells the preprocessor to search for a file
named stdio.h and places it in the program. <> tells to look in the
‘include’ directory for the file stdio.h. Whereas stdio.h” tells the
preprocessor to look in the current directory.

Character input and output:


Getchar(): It is the most basic way of reading a character
variable=getchar()
By writing this we can enter any amount of characters that we want
but only the first character typed will be stored. The similar
functions to this are getch() and getche().
Putchar (): It is a complementary function to getchar as it is used
to display a single character putchar(variable).
Formatted input and output:
The two functions getchar and putchar are unformatted I/O
functions whereas cout and cin are the formatted I/O functions.
The difference between two categories is that the formatted
functions allow us to input by using keyboard and get output on the
screen according to our requirements.
Control flow statements in ‘C++’

These statements help in decision making and repetition of various


instructions.
1. if statement: it is the general decision making statement.
Syntax: if(expression)
program statement;
The expression is evaluated if it is TRUE (i.e. non-zero value)
otherwise the compiler will skip the statement.
e.g. if (5>3)
cout<<my name is Mani;

The additional part of the “if” statement is “else” which makes


the full syntax as:
if(expression)
statement 1;
else
statement 2;
When the expression evaluates to true then the statement 1 is
executed otherwise statement 2 is executed.
e.g. if(code==’d’)
amount =amount + money;
else
amount =amount – money;
There can be many conditions that are to be performed at the
same time then we can use nested if-else statements:
Syntax: if(expression)
{
if(expression)
statement;
else
statement;
}
else
{
if(expression)
statement;
}
The above used nested statements can be used as a regular trend
which is named as else-if statement block.
Syntax: if(expression 1)
statement1;
else if(expression 2)
statement2;
else if(expression 3)
statement3;
……………..
…………….
else
statementn;
2. While statement: the while statement is used for repetition. The
working of while statement is as follows:
The expression is evaluated first. If it evaluates to true then the
statements are executed and the increments occur and the
expression is evaluated again. This cycle continues until the
expression evaluates to false.
Syntax: while(expression)
{
statement;
increment/decrement;
}
e.g. #include<stdio.h>
void main()
{
int i= 0;
while(i <=10)
{
i++;
cout<< “value of i is ”<< i;
}
}
Firstly, the initial value of i i.e.0 passes through while statement,
clearly the condition becomes true. The inside statements are
executed first value of i increases by one and secondly, value of
increased i is printed.
3. for loop: the function of for loop is just the same as while loop
but the syntax is different.
Syntax: for (init expression; condition; loop expression)
Statement block;
The three parts inside loop can be omitted singly.
The init expression tells about the initialization of the variable.
Second statement tells the condition which has to be true for the
loop to work.
Third statement tells about the increment or decrement of the
variable.
e.g. #include<stdio.h>
void main()
{
int i, sum;
sum=0;
for(i=0; i<10; i++)
sum= sum+ i;
cout<< “the output = ” << sum;
}
The above program adds the value of i every time the condition
becomes true, and in the end value of sum is printed. The loop
continues until i become 9.

4. do-while loop: Its purpose is just the same as that of while loop,
but the functioning is entirely different from while loop.

Syntax: do
Statement;
While (expression);
The difference between while and do-while is that the do-while
loop works once even if the condition becomes false in the
beginning.
e.g. #include<stdio.h>
void main()
{
int i= 1, sum;
Sum=0;
do
sum = sum + i;
while (i<10);}
Here before checking of condition takes place the compiler
already adds 1 to sum, hence the result will be different from the
for loop addition.

5. switch-case statement: It is used when we have to take decision


at a single time, in this we use the condition as alternatives i.e. it
is our convenience which condition to call.

Syntax: switch (integer expression)


{
case constant: statement;
case constant: statement;
……………………..
………………………
default: statement;
}
The expression inside the switch statement tells the compiler
which case first to be evaluated. When the compiler reaches the
mentioned case it evaluates the instructions but doesn’t stop
after that, it also evaluates the coming statements also, therefore
to remove this we use break statement at the end of each case
which automatically brings the compiler out of the case after
compiling it.
6. break: It allows us to exit from the while loop or the for loop.
As soon as the break statement comes the compiler comes out of
the loop.
7. continue: It allows us to continue the execution of the loop from
the beginning and leaving all the statements following it i.e. as
soon as the continue statement is encountered the loop goes to
its starting point.

Functions

A function is a set of instructions which perform a particular task.


In c language it can be a combination of set of different small
functions which perform different task. There are two types of
functions:

1. Library functions.
2. User defined functions.

Library functions are those functions which are already defined


for the compiler. e.g. printf(), scanf() functions are already defined
in the C library in stdio.h header file.

User defined functions are those which are created by a


programmer for a particular task. The steps involved in creating and
using a user defined function are as following:

1. Declaring a function prototype.


2. Defining the function.
3. Calling the function.

e.g. #include <stdio.h>


welcome()
{
cout<<"you are welcome";
}
main()
{
cout<<“hello\n”;
welcome();
cout<<“have a nice day”;
}
During the execution of main() as soon as the compiler reaches
the function welcome() it automatically goes out of main() and
firstly execute welcome() then the further statements of main().

Passing arguments to a function


It can be done by two processes:
1. Call by value process.
2. Call by reference process.
When we pass the value of the variables as such to a function the
process is known as call by value. e.g.

Recursive functions

A function that calls itself is known as the recursive function. This


concept can be used as a replacement of looping. e.g.
#include<stdio.h>
main()
{
int num;
cout<<"nter the number: ";
cin>>num;
factorial= fact (num);
cout<<“the value of the factorial is: "<< factorial;
}
fact (n)
int n;
{
if(n== 1)
return (1);
else
return (n* factorial (n-1));
}
The above program regularly calls the function and returns the
value of factorial.

Arrays

It is a collection of the variables that have same name and data


type.
General definition of single dimensional array:
Storage-class data-type array[expression]
e.g. int x [100]; char name[30];
Different elements of array can be represented as x[0], x[1], x[2],
x[3]…, x[n].
Initialization of an array:
Storage-class data-type array[expression]= {value1, value2 …
valuen}
It is our choice to give the array size during initializing, because a
blank already sets the space for the entered values.
e.g. int y[] = {1, 2, 3, 4, 5};
char y[]= “COMPUTER”;
Structures
A structure is a collection of one or more variables of different type
grouped together having a single name.
General format:
struct tag-name
{
data-type member1;
data-type member2;
…………..
data-type member n;
} variable1, variable2… variable n;

Accessing structure elements:


The structure variable can be accessed by using dot (.) operator or
arrow (->) operator.
We write variable.member to access the variable using dot (.)
operator, for using arrow operator we use the pointers.
The dot operator is also known as member operator. It has the
highest precedence over all the unary and binary operators.

Unions
Unions is just same as the structure definition, this is also used to
group together same variables.
The difference between structure and union is that in union all the
variables are given same memory location whereas in structure
each variable is given separate memory, therefore the union is used
to save the wastage of memory.
storage-class union tag-name
{
data-type member1;
data-type member2;
………………….
data-type membern;
} variable1, variable2… variablen;

OOPS

Both the programming languages c & c++ are related to each other.
In real sense we can directly say that c++ language is extension
(increment) of c language by observing the “++” operator which
tells the incrementation by one in c language.
All the above written topics are used in nearly the same way as in C
language.
C++ contains the new concept of OOPS (object oriented
programming), rest of the conceptual portion of c++ is same as that
of c language. The small difference between them is of keywords
e.g. c++ uses cout and cin as their input and output functions
whereas c uses printf and scanf on the same place.
OOPS concept

Object oriented programming is a conceptual approach. It’s main


features are:
1. Data abstraction.
2. Data hiding and encapsulation.
3. Polymorphism.
4. Inheritance.
The most important feature of C++ is the data abstraction called

Class.
A class description consists of two parts:
(a) class definition of the components (data members and member
functions).
(b) class implementation or definition of member functions.
e.g. class person
{
private:
char name[20];
int age;
double height;
public:
void getdata(void);
void setdata(char *string, int a, double h);
void showdata(void);
};

The data members and member functions are defined in three types
of accessibility options.
1. private: The private data members and member functions are
accessible only within the class description. They are hidden
from rest of program, therefore it comes under the concept of
data hiding.
2. public: Those which can be used outside of the class definition.
They act as a route between private members and rest of the
program.
3. protected: It is helpful in inheritance, any member declared as
protected is accessible by the member function within its class
and any immediately derived class, cannot be accessed by
outside function of these two classes.

Classes and objects


A class description like a structure description will not reserve
space in memory. When actual data objects are created they reserve
the pace for individual data members.
Person p1, p2;
name………… name…………….
age………….. age………………
height……….. height……………
p1 p2
The member functions can be accessed as:
p1.getdata();
p2.setdata();
p3.showdata();
The setdata(), getdata(), and the showdata(), functions of class
person are unique copy for different objects.
We can separate the program in two segments one containing the
class with the description of data members and member functions,
and the second part containing the main() function.
The first part is stored as file.h and will be directly used in the
second segment as #include”file.h”.
Characteristics of OOPS:
1. In oop data and a function that update on that data are combined
into a single unit known as object.
2. A class is description of a number of similar objects.
3. Inheritance, each sub-class share common characteristics with
the class from which it is derived.
4. Reusability: A particular class is created and distributed to
other programmer for use in their other programs.
5. Polymorphism: One thing with several forms known as
overloading. The processes are known as operator overloading
and function overloading.
Operator overloading: e.g. a + operator can be made useful to
add two different strings.

Function overloading: The function with same name but with


different parameters.
Add(int a, int b);
Add(int a, float b);
6. Data encapsulation: it includes the concept of building data and
function together.
7. Data hiding: protecting data from access by unauthorized
function.
8. Data abstraction: it is the concept of simplifying the real world
concept into its essential elements representing essential features
without including background details.
Constructors
We define the values to the variables of functions by creating a new
function, to reduce this problem and to initialize the variable at the
time of calling of function in main() we use the concept of
constructors.
Constructors have the same name as that of class name.
Two ways to initialize a constructor inside main():
1. person p= person(“ram”,40,5.7);
2. person p(“ram”,40,5.7);
Each and every time a function is called the constructor will be
automatically be called, therefore to reduce this effect and made use
of the constructor required number of time we use default
constructors. It is a blank function.

Destructor function
When an object is created it calls the constructor function.
whenever a program exits all its objects are expired, during this
process the program calls a function called destructor function.
The destructor function helps undo the work of the constructor. i.e.
if constructor uses new operator then the destructor uses delete
operator.
The destructor has the same name as that of class followed by a
tilde(~) sign. It doesnot have any return type. e.g. ~person(void).

Friends and operator overloading(POLYMORPHISM)

A friend function is a member function that are useful in accessing


the private data members. To invoke a friend function objects are
not required. Objects are passed as arguments to the friend
function.

Operator overloading

C++ provides a rich collection of various operators, it enables an


operator to exhibit more than one operation, e.g. a simple addition
operator (+) can be used to add two numbers can be made to add
two strings.
Rules of overloading:
1. . .* :: ?: sizeof # = () [] -> are the operators that cannot be
overloaded.
2. operators already predefined in c++ compiler can be only
overloaded.
3. operator cannot change operator templates e.g. the increment
operator is used only as unary operators, it cannot be used as a
binary operator.
4. overloading an operator doesnot change its basic meaning e.g.
the ‘+’ operator cannot be overloaded to subtract two objects.

Function overloading

Same function name can be used for different purposes.


Class a
{
Public:
Void add()
{
cout<<”enter a & b”;
cin>>a>>b;
c=a+b;
cout<<c;
}
void add(int a,int b)
{
int c;
c=a-b;
cout<<c;
}
};
void main()
{
clrscr();
a z;
z.add();
z.add(8.4);}

Inheritance
The formation of derived classes out of the base class and using the
visibility options according to our requirement is known as
inheritance.
The definition of derived class is given by:
Class derive
d::public/private/protected base
{
public:
void display(void);
};
The way in which a derived class is being called decide how the
variables get the accessibility. To know the accessibility we use the
chart below:
Base Public Private Protected
class derivation derivation derivation
visibility
Private Not Not Not
inherited inherited inherited
Protected Protected Private Protected
Public Public Private Protected

Types of inheritance:

1. Single inheritance: it includes forming of a derived class from


one single class.

Class father
{
private:
int age;
char name[20];
public:
void get();
void show();
};
class mother: public father
{
private:
int age;
char name[20];
public:
void get();
void show();
};
2. Multilevel inheritance: The mechanism of deriving a class
from another derived class.

Class father
{
private:
int age;
char name[20];
public:
void get();
void show();
};
class mother: public father
{
private:
int age;
char name[20];
public:
void get();
void show();
};
class daughter:public mother
{
private:
int std;
char name[20];
public:
void get();
void show();
};

3. Multiple inheritance: when a derived class is made by using


two or more base classes.

Class father
{
private:
int age;
char name[20];
public:
void get();
void show();
};
class mother
{
private:
int age;
char name[20];
public:
void get();
void show();
};
class daughter:public father,public mother
{
private:
int std;
char name[20];
public:
void get();
void show();
};

4. Hierarchical inheritance: if one class may be inherited by more


than one class.

Class father
{
private:
int age;
char name[20];
public:
void get();
void show();
};
class daughter:public father
{
private:
int std;
char name[20];
public:
void get();
void show();
};
class son:public father
{
private:
int rollno;
char name[20];
public:
void get();
void show();
};

5. Hybrid inheritance: it is the mixture of multiple and


hierarchical.
Class student
{
private:
int rollno;
public:
void get();
void show();
};
class test:public student
{
protected:
float part1, part2;
public:
void getm();
void showm();
};
class sports
{
protected:
float score;

public:
void gets();
void shows();
};
class result:public test, public sports
{
float total;
public:
void display();
};
File handling in C++

Header files
ifstream, ofstream, and fstream classes are declared in the fstream.h
file. This file also includes the iostream.h header file.

String input/output
Write:
#include<stdio.h>
void main()
{
ofstream outfile(“test.txt”);
outfile<<”hello how are you\n”;
outfile<<”welcome\n”;
}

Read:
void main()
{
const int max=80;
char buffer [max];
ifstream infile(“test.txt”);
while(infile)
{
infile.getline(buffer, max);
cout<<buffer;
}
}

Character input and output:


The put() and get() function which are member of ofstream and
ifstream respectively are used to input and output a single character
at a single time.
Write:
void main()
{
char str[]=”time is precious”;
ofstream outfile(“test.txt”);
for(int j=0;j<strlen(str);j++)
outfile.put(str[j]);
}
Read:
void main()
{
char ch;
ifstream infile(“test.txt”);
while(infile)
{
infile.get(ch);
cout<<ch;
}
}

Object input and output:


Write:
#include<fstream.h>
class person
{
private:
char name[20];
int age;
public:
void getdata();
{
cout<<”enter name:”;
cin>>name;
cout<<”enter age”;
cin>>age;
}
};
void main()
{
person p;
p.getdata();
ofstream outfile(“person.dat”);
outfile.write(char *)&p,sizeof(p));
}

Read:
#include<fstream.h>
class person
{
private:
char name[20];
int age;
public:
void showdata()
{
cout<<”name”<<name;
cout<<”age”<<age;
}
};

void main()
{
person p;
ifstream infile(“person.dat”);
infile.read((char*)&p;sizeof(p));
p.showdata();
}
Applications of ‘C/C++’:
• General applications.
• Database systems.
• Spread sheets.
• Graphic packages.

• Word processors.
• Office automation.
• Scientific/engineering applications.
/************************************************************/

#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<iomanip.h>
#include<stdio.h>
#include<stdlib.h>

/************************************************************/

/************************************************************/

class personal

char nm[20],fnm[20],cl[10],add[40],city[15],state[15],phc[10];
int age,dd,mm,yy;
float phn,zpcode;
public:
int rn;
void get(void);
void put(void);

};

/************************************************************/
/************************************************************/

class marks

char sb[10][10],gd,ans;
int m[10],mm[10],ts,tmm,tmo;
float av,per;
public:
int rn1;
void get1(void);
void put1(void);
void cal(int mm[],int ts,int m[]);

};

/************************************************************/
/************************************************************/

void personal::get(void)

cout<<endl<<setw(3)<<"Name : ";
cout<<endl<<setw(3)<<"Father's Name : ";
cout<<endl<<setw(3)<<"Roll No. : ";
cout<<endl<<setw(3)<<"Class : ";
cout<<endl<<setw(3)<<"Age : ";
cout<<endl<<setw(3)<<"D.O.B : "; gotoxy(22,10); cout<<setw(3)<<"/"
<< setw (3) <<"/" <<setw(3) <<" (dd/mm/yy)";
cout<<endl<<setw(3)<<"City : ";
cout<<endl<<setw(3)<<"State : ";
cout<<endl<<setw(3)<<"Zip/Postal Code : ";
cout<<endl<<setw(3)<<"Phone Code : ";
cout<<endl<<setw(3)<<"Phone no. : ";
gotoxy(22,5);
cin>>nm;
gotoxy(22,6);
cin>>fnm;
gotoxy(22,7);
cin>>rn;
gotoxy(22,8);
cin>>cl;
gotoxy(22,9);
cin>>age;
gotoxy(22,10);
cin>>dd;
gotoxy(25,10);
cin>>mm;
gotoxy(28,10);
cin>>yy;
gotoxy(22,11);
cin>>city;
gotoxy(22,12);
cin>>state;
gotoxy(22,13);
cin>>zpcode;
gotoxy(22,14);
cin>>phc;
gotoxy(22,15);
cin>>phn;

/************************************************************/

/************************************************************/

void personal :: put (void)


{
cout<<endl<<"Name : "<<nm;
cout<<endl<<"Father's Name : "<<fnm;
cout<<endl<<"Roll No. : "<<rn;
cout<<endl<<"Class : "<<cl;
cout<<endl<<"Age : "<<age;
cout<<endl<<"D.O.B : "<<dd<<"/"<<mm<<"/"<<yy;
cout<<endl<<"City : "<<city;
cout<<endl<<"State : "<<state;
cout<<endl<<"Zip/Postal Code : "<<setprecision(0)<<zpcode;
cout<<endl<<"Phone Code : "<<phc;
cout<<endl<<"Phone no. : "<<setprecision(0)<<phn;
}

/************************************************************/

/************************************************************/

void comp(int rn1);

/************************************************************/
/************************************************************/

void marks::get1(void)
{
cout<<"Roll No. : ";cin>>rn1;
comp(rn1);
ans='y';
ts=0;
for(int i=0;ans=='y';i++)
{
ts++;
cout<<endl<<"subject"<<ts<<" : ";
cin>>sb[i];
cout<<"Marks Obtained in "<<sb[i]<<" : ";
cin>>m[i];
cout<<"Maximum Marks For "<<sb[i]<<" : ";
cin>>mm[i];
opt:
cout<<endl<<"Want to Add more Subject(s)--(y/n) : ";
cin>>ans;
if(ans!='y'&&ans!='n')
{
cout<<endl<<"\n\n\a !Incorrect entry press 'y' for yes and
'n' for no \a";
goto opt;
}
if(ans=='y'&&ts==10)
{
cout<<endl<<"\n\n\a!Space available for total no. of
subjects is full\a";
ans='n';
}
}
cout<<endl<<"Total no. of Subjects : "<<ts;
cal(mm,ts,m);
}
/************************************************************/

/************************************************************/

void marks::cal(int mm[],int ts,int m[])


{
tmm=0;
tmo=0;
for(int j=0;j<ts;j++)
{
tmm=tmm+mm[j];
tmo=tmo+m[j];
}
cout<<endl<<"Total Marks : "<<tmm;
cout<<endl<<"Total Marks Obtained : "<<tmo;
av=(float)tmo/ts;
cout<<endl<<"Average Marks : "<<setprecision(2)<<av;
per=(float)(tmo*100)/tmm;
cout<<"Pecentage Marks : "<<setprecision(2)<<per<<" %";
if(per>90)
gd='A';
else if(per<=90&&per>80)
gd='B';
else if(per<=80&&per>68)
gd='C';
else if(per<=68&&per>55)
gd='D';
else if(per<=55&&per>=43)
gd='E';
else if(per<43)
gd='F';
if(gd=='F')
cout<<endl<<"Remarks : FAIL"<<endl<<"Grade : "<<gd;
else
cout<<endl<<"Remarks : PASS"<<endl<<"Grade : "<<gd;
}
/************************************************************/

/************************************************************/

void marks::put1(void)
{
cout<<endl<<"Roll no. : "<<rn1;
cout<<endl<<"S.no."<<setw(8)<<"Subjects"<<setw(8)<<"Marks" ;
for(int i=1;i<=ts;i++)
{
cout<<endl<<i;gotoxy(9,i+3);cout<<sb[i-1];
gotoxy(25,i+3);cout<<m[i-1];
}
cout<<endl<<"Total no. of Subjects : "<<ts;
cout<<endl<<"Total Marks Obtained : "<<tmo;
cout<<endl<<"Total Marks : "<<tmm;
cout<<endl<<"Average Marks : "<<setprecision(2)<<av;
cout<<endl<<"Percentage Marks : "<<setprecision(2)<<per<<"%";
cout<<endl<<"Grade : "<<gd;
if(gd=='F')
cout<<endl<<"Remarks : FAIL";
else
cout<<endl<<"Remarks : PASS";
}

/************************************************************/

/************************************************************/
void add (void);
void mod (void);
void del (void);
void search (void);
void list (void);
void add1 (void);
void mod1 (void);
void del1 (void);
void search1 (void);
void list1 (void);
/************************************************************/

/************************************************************/

personal per;
marks mak;
ofstream f1;
ifstream f2;
fstream f;

/***********************************************************/

/***********************************************************/

void main()
{
xyz:
clrscr();
cout<<endl<<"1.Personal Details"<<endl<<"2.Marks
Details"<<endl<<"3.Exit";
int s;
cout<<endl<<"enter 1 for personal details , 2 for marks details and 3 to
exit : ";
cin>>s;
switch(s)
{
case 1:
{
abc:
clrscr();
cout<<endl<<"PERSONAL:";
cout<<endl<<"1.Add\n2.Modify\n3.Delete\n4.Search\n5.Li
st\n6.Back";
cout<<"\nenter the serial no. of the operation you want to
perform : ";
int e;
cin>>e;
switch(e)
{
case 1:
{
char rep='y';
while(rep=='y')
{
clrscr();
add();
cout<<"\nwant to add more record(s)-
(y/n)";
cin>>rep;
}
goto abc;
}

case 2:
{
clrscr();
mod();
goto abc;
}
case 3:
{
clrscr();
del();
goto abc;
}
case 4:
{
clrscr();
search();
goto abc;
}
case 5:
{
clrscr();
list();
goto abc;
}
case 6:
{
clrscr();
goto xyz;
}
default:
{
clrscr();
goto abc;
}
};
}

case 2:
{
pqr:
clrscr();
cout<<endl<<"MARKS:";
cout<<endl<<"1.Add\n2.Modify\n3.Delete\n4.Search
\n5.List\n6.Back";
cout<<"\nenter the serial no. of the operation you want to
perform : ";
int h;
cin>>h;
switch(h)
{
case 1:
{
clrscr();
add1();
goto pqr;
}
case 2:
{
clrscr();
mod1();
goto pqr;
}
case 3:
{
clrscr();
del1();
goto pqr;
}
case 4:
{
clrscr();
search1();
goto pqr;
}

case 5:
{
clrscr();
list1();
goto pqr;
}
case 6:
{
clrscr();
goto xyz;
}
default:
{
clrscr();
goto pqr;
}
};
}
case 3:
{
exit(0);
}
default:
{
clrscr();
goto xyz;
}
};
}

/************************************************************/

/************************************************************/

void add (void)

{
cout<<endl<<"PERSONAL:ADD:";
cout<<"\n\n";
f.open("mi.txt",ios::app);
per.get();
f.write((char *)&per,sizeof(per));
f.close();

/************************************************************/

/************************************************************/

void mod (void)


{
int c,k=0;
f.open("mi.txt",ios::in|ios::out);
char ans='y';
while(ans=='y')
{
cout<<"enter roll no. whose record is to be modified : ";
cin>>c;
clrscr();
cout<<endl<<"PERSONAL:MODIFY:";
cout<<"\n\n";
while(f.read((char *)&per,sizeof(per)))
{
if(per.rn==c)
{
per.get();
f.seekg(-sizeof(per),ios::cur);
f.write((char *)&per,sizeof(per));
k=1;
break;
}
}
if(k==0)
cout<<"\n\a!Record DOES NOT Exist\a";
cout<<"\nwanna modify more records--(y/n)";
cin>>ans;
f.close();
}
}

/************************************************************/

/************************************************************/

void search(void)
{
int c,k;
f2.open("mi.txt");
char ans='y';
while(ans=='y')
{
cout<<"enter roll no. whose record is to be searched : ";
cin>>c;
clrscr();
cout<<endl<<"PERSONAL:SEARCH:";
cout<<"\n\n";
k=0;
while(f2.read((char *)&per,sizeof(per)))
{
k=0;
if(per.rn==c)
{
per.put();
k=1;
break;
}
}
if(k==0)
cout<<"\n\a!Record DOES NOT Exist\a";
cout<<"\nwanna search more records--(y/n)";
cin>>ans;
f2.close();
}
}

/************************************************************/

/************************************************************/

void del (void)


{
int c;
f1.open("new.txt");
f2.open("mi.txt");
char ans='y';
while(ans=='y')
{
cout<<endl<<"PERSONAL:DELETE:";
cout<<"\n\n";
cout<<"enter roll no. whose record is to be deleted : ";
cin>>c;
clrscr();
cout<<endl<<"PERSONAL:DELETE:";
cout<<"\n\n";
while(f2.read((char *)&per,sizeof(per)))
{
if(per.rn!=c)
{
f1.write((char *)&per,sizeof(per));
}
}
f1.close();
f2.close();
remove("mi.txt");
rename("new.txt","mi.txt");
cout<<"\nwanna delete more records--(y/n)";
cin>>ans;
f.close();
}
}

/************************************************************/

/************************************************************/

void list (void)


{
f2.open("mi.txt");
cout<<endl<<"PERSONAL:LIST:";
cout<<"\n\n";
int i=0;
while(f2.read((char *)&per,sizeof(per)))
{ per.put();
i++;
getch();
clrscr();}
f2.close();
if(i==0)
{ cout<<"NO Results to display";
getch();}

/************************************************************/

/************************************************************/

void add1 (void)


{
cout<<endl<<"MARKS:ADD:";
cout<<"\n\n";
f.open("mi.txt",ios::app);
mak.get1();
f.write((char *)&mak,sizeof(mak));
f.close();
}

/************************************************************/

/************************************************************/

void mod1 (void)


{
int c,k=0;
f.open("mi.txt",ios::in|ios::out);
char ans='y';
while(ans=='y')
{
cout<<"enter roll no. whose record is to be modified : ";
cin>>c;
clrscr();
cout<<endl<<"MARKS:MODIFY:";
cout<<"\n\n";
while(f.read((char *)&mak,sizeof(mak)))
{
if(mak.rn1==c)
{
mak.get1();
f.seekg(-sizeof(mak),ios::cur);
f.write((char *)&mak,sizeof(mak));
k=1;
break;
}
}
if(k==0)
cout<<"\n\a!Record DOES NOT Exist\a";
cout<<"\nwanna modify more records--(y/n)";
cin>>ans;
f.close();
}
}
/************************************************************/

/************************************************************/

void search1(void)
{
int c,k;
f2.open("mi.txt");
char ans='y';
while(ans=='y')
{
cout<<"enter roll no. whose record is to be searched : ";
cin>>c;
clrscr();
cout<<endl<<"MARKS:SEARCH:";
cout<<"\n\n";
k=0;
while(f2.read((char *)&mak,sizeof(mak)))
{
k=0;
if(mak.rn1==c)
{
mak.put1();
k=1;
break;
}
}
if(k==0)
cout<<"\n\a!Record DOES NOT Exist\a";
cout<<"\nwanna search more records--(y/n)";
cin>>ans;
f2.close();
}
}

/************************************************************/
/************************************************************/
void del1 (void)
{
int c;
f1.open("new.txt");
f2.open("mi.txt");
char ans='y';
while(ans=='y')
{
cout<<endl<<"MARKS:DELETE:";
cout<<"\n\n";
cout<<"enter roll no. whose record is to be deleted : ";
cin>>c;
clrscr();
cout<<endl<<"MARKS:DELETE:";
cout<<"\n\n";
while(f2.read((char *)&mak,sizeof(mak)))
{
if(mak.rn1!=c)
{
f1.write((char *)&mak,sizeof(mak));
}
}
f1.close();
f2.close();
remove("mi.txt");
rename("new.txt","mi.txt");
cout<<"\nwanna delete more records--(y/n)";
cin>>ans;
f.close();
}
}

/************************************************************/
/************************************************************/

void list1 (void)


{
f2.open("mi.txt");
cout<<endl<<"MARKS:LIST:";
cout<<"\n";
int i=0;
while(f2.read((char *)&mak,sizeof(mak)))
{
mak.put1();
i++;
getch();
clrscr();}
f2.close();
if(i==0)
{ cout<<"NO Results to display";
getch();}

/************************************************************/
/************************************************************/

void comp(int rn1)


{
f2.open("mi.txt");
char d;int t=0;
while(f2.read((char *)&per,sizeof(per)))
{
if(per.rn==rn1)
{
t=1;
break;
}
}
if(t==0)
{
cout<<"\n this roll no. has no personal record\n wanna add its
personal record--(y/n)";
cin>>d;
if(d=='y')
{
clrscr();
add();
}
}
}

/************************************************************/

You might also like