0% found this document useful (0 votes)
52 views136 pages

Final Oop 1941060

The document describes an index for practical and practice programs completed as part of an Object Oriented Programming lab. It includes 13 practical programs completed between October 2020 and January 2021 on topics like arithmetic operations, constructors, operators, inheritance, and file handling. It also lists 7 practice programs completed between November 2020 and January 2021 involving concepts like friend functions, operator overloading, classes, stacks, queues, and polymorphism.

Uploaded by

Yash Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views136 pages

Final Oop 1941060

The document describes an index for practical and practice programs completed as part of an Object Oriented Programming lab. It includes 13 practical programs completed between October 2020 and January 2021 on topics like arithmetic operations, constructors, operators, inheritance, and file handling. It also lists 7 practice programs completed between November 2020 and January 2021 involving concepts like friend functions, operator overloading, classes, stacks, queues, and polymorphism.

Uploaded by

Yash Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 136

OBJECT ORIENTED PROGRAMMING LAB

NAME: YASH PATIL


PRN : 1941062
CLASS: SY COMPUTER
BATCH : S3

INDEX FOR PRACTICAL


SR.NO NAME DOP DOC

1 Arithmetic operation 16/10/2020 16/10/2020

2 Constructor overloading 23/10/2020 23/10/2020

3 Function overloading 30//10/2020 30//10/2020

4 Friend function 18/12/2020 18/12/2020

5 Unary operator 13/10/2020 13/10/2020

6 Binary Operator 27/11/2020 27/11/2020

7 Dynamic memory allocation 04/12/2020 04/12/2020

8 Virtual Base Class 01/01/2021 01/01/2021

9 Manipulators 11/12/2020 11/12/2020


10 Multiple inheritance 01/01/2021 01/01/2021

11 Template matrix operation 11/12/2020 11/12/2020

12 File handling 01/01/2021 01/01/2021

13 Shape class 04/12/2020 04/12/2020

INDEX FOR PRACTICE PROGRAM

SR. NAME DOP DOC


NO

1 Friend function and friend class 18/11/2020 18/11/2020

2 Overloading = operator 25/11/2020 25/11/2020

3 Student class 25/11/2020 25/11/2020

4 Stack and queue 04/01/2021 04/01/2021

5 Calculating perimeter 05/01/2021 05/01/2021

6 File handling 05/01/2021 05/01/2021

7 Polymorphism 18/12/2020 18/12/2020


CO207U Object Oriented Programming Lab

Government College of Engineering, Jalgaon


(An Autonomous Institute of Government of Maharashtra)

PRN: 1941060 Name of the Student: Yash Patil

Class :S.Y. B.tech Semester :III DOP : 16/10/2020 DOC : 16/10/2020

Subject Teacher: Shrutika Mahajan Subject Coordinator:


Aim: Write a program for a simple class and object. Performing simple arithmetic operations using

C ++ class and object like, Addition, Subtraction, Multiplication & Division.

Compiler used: We used the g++ compiler to compile the C++ program.

Operating System used: Ubuntu

Theory:

The main purpose of C++ programming is to add object orientation to the C programming

language and classes are the central feature of C++ that supports object-oriented programming and

are often called user-defined types.

A class is used to specify the form of an object and it combines data representation and

methods for manipulating that data into one neat package. The data and functions within a class are

called members of the class.

A class definition starts with the keyword class followed by the class name; and the class

body, enclosed by a pair of curly braces. A class definition must be followed either by a semicolon

or a list of declarations. For example, we defined the Box data type using the keyword class as

follows −

class Box {

public:

double length; // Length of a box

double breadth; // Breadth of a box

double height; // Height of a box

};

The keyword public determines the access attributes of the members of the class that

follows it. A public member can be accessed from outside the class anywhere within the scope of
the class object. You can also specify the members of a class as private or protected which we

will discuss in a sub-section.

Define C++ Objects

A class provides the blueprints for objects, so basically an object is created from a class. We

declare objects of a class with exactly the same sort of declaration that we declare variables of

basic types. Following statements declare two objects of class Box −

Box Box1; // Declare Box1 of type Box

Box Box2; // Declare Box2 of type Box

Both of the objects Box1 and Box2 will have their own copy of data members.

Accessing the Data Members

The public data members of objects of a class can be accessed using the direct member access

operator (.).

This program demonstrates how classes and its objects are created in program. Using

add(),sub(),mul(),div(),mod() member functions arithmetic operations are performed.

Pseudo Code:

1. Start.

2. Declare the class Arithmetic

3. Declare the private and public data members and 5 member functions.

4. Define the member functions add(),sub(),mul(),div(),mod() in class and returning

statements.

5. In main function create an object of a class Arithmetic class

6. Access all member functions such as add(),sub(),mul(),div(),mod()by calling it using

object(“ .” operator)

7. Print results of all arithmetic operations.

8. Stop

Conclusion:

I perform a program for a simple class and object. Performing simple

Arithmetic operations like addition , subtraction, multiplication and division.


// Yash Patil

//PRN : 1941060

//S3 Batch

#include<iostream.h>

#include<process.h>

#include<conio.h>

class Arith

private:

int x,y;

public:

int add();

int sub();

int mul();

int div();

};

int Arith::add()

cout<<"Enter the x value"<<endl;

cin>>x;

cout<<"Enter the y value"<<endl;

cin>>y;

return(x+y);

int Arith::sub()

cout<<"Enter the x value"<<endl;

cin>>x;

cout<<"Enter the y value"<<endl;

cin>>y;

return(x-y);
}

int Arith::mul()

cout<<"Enter the x value"<<endl;

cin>>x;

cout<<"Enter the y value"<<endl;

cin>>y;

return(x*y);

int Arith::div()

cout<<"Enter the x value"<<endl;

cin>>x;

cout<<"Enter the y value"<<endl;

cin>>y;

return(x/y);

main()

Arith obj;

char ch;

clrscr();

while(1)

cout<<"a:Addition"<<endl;

cout<<"s:Subtraction"<<endl;

cout<<"m:Multiply"<<endl;

cout<<"d:Division"<<endl;

cout<<"e:exit"<<endl;

cout<<"Enter your Choice"<<endl;

cin>>ch;
switch(ch)

case 'a':

int a=obj.add();

cout<<"Addtion Result="<<a<<endl;

break;

case 's':

int s=obj.sub();

cout<<"Subtract Result="<<s<<endl;

break;

case 'm':

int m=obj.mul();

cout<<"Multiply Result="<<m<<endl;

break;

case 'd':

int d=obj.div();

cout<<"Division Result="<<d<<endl;

break;

case 'e':

exit(0);

}
CO207U Object Oriented Programming Lab

Government College of Engineering, Jalgaon


(An Autonomous Institute of Government of Maharashtra)

PRN: 1941060 Name of the Student: Yash Patil

Class :S.Y. B.tech Semester :III DOP : 23/10/2020 DOC : 23/10/2020

Subject Teacher: Shrutika Mahajan Subject Coordinator:

Aim: Write a C++ program to calculate multiplication of two numbers; use parameterized and

default constructor.

Compiler used: We used the g++ compiler to compile the C++ program.

Operating System used: Ubuntu

Theory:

The Class Constructor

In C++, constructor is a special method which is invoked automatically at the time of object

creation. It is used to initialize the data members of new object generally. The constructor in C++

has the same name as class or structureThere can be two types of constructors in C++.

● Default constructor

● Parameterized constructor

A class constructor is a special member function of a class that is executed whenever we create

new objects of that class. A constructor will have exact same name as the class and it does not have

any return type at all, not even void. Constructors can be very useful for setting initial values for

certain member variables.

C++ Default Constructor

A constructor which has no argument is known as default constructor. It is invoked at the time of

creating object

For e.g.

class Line {

public:

void setLength( double len );


double getLength( void );

Line(); // This is the constructor

private:

double length;

};

C++ Parameterized Constructor

A constructor which has parameters is called parameterized constructor. It is used to provide

different values to distinct objects. Let's see the simple example of C++ Parameterized Constructor.

C++ Copy Constructor

A Copy constructor is an overloaded constructor used to declare and initialize an object from

another object.

Copy Constructor is of two types:

o Default Copy constructor: The compiler defines the default copy constructor. If the user

defines no copy constructor, compiler supplies its constructor.

o User Defined constructor: The programmer defines the user-defined constructor.

Syntax Of User-defined Copy Constructor:

Class_name(const class_name &old_object);

For e.g.

class A

A(A &x) // copy constructor.

// copyconstructor.

If we have to use multiple constructors in one program,we can use it in by overloading constructors

Fore.g
Consider a class Student

class student

.......

..........

student() // default constructor

student(int a, int b) //parameterized constructor

student(Student &s) //copy constructor

Pseudo Code:

1. Start.

2. Declare the class Multiplication

3. Define the constructors Multiplication() as a default constructor and Multiplication(int a,int

b) as a parameterised constructor in class with body.

4. define a common method display() to show result of multiplication in both constructors

5. In main function create an objects of a class Multiplication class

a. Multiplication m1 for default constructor.

b. Multiplication m2(12.10) for parameterised constructor.

c. Call a display method to show results

6. Stop

Conclusion:

I perform a program to calculate multiplication of two numbers; by using parameterized and default
constructor.

//Name : Yash Patil

//PRN : 1941060

//S3 Batch

#include<iostream>

Using namespace std;

class multiplication

{
int a ,b ,mul ;

public:

multiplication()

cout<<”default constructor”<<endl;

multiplication(int p,int q)

a = p;

b =q;

mul = a*b;

void display()

cout<<a<<”*”<<b<<”=”<<mul<<endl;

};

int main()

multiplication m1 , m2(14,12);

m2. Display();
CO207U Object Oriented Programming Lab

Government College of Engineering, Jalgaon


(An Autonomous Institute of Government of Maharashtra)

PRN: 1941060 Name of the Student: Yash Patil

Class :S.Y. B.tech Semester :III DOP : 30/10/2020 DOC : 30/10/2020

Subject Teacher: Shrutika Mahajan Subject Coordinator:

Aim: Write a C++ program to calculate the area of a rectangle,triangle and circle using function

overloading

Compiler used: We used the g++ compiler to compile the C++ program.

Operating System used: Ubuntu

Theory :

Function Overloading is defined as the process of having two or more functions with the

same name, but different in parameters is known as function overloading in C++. In function

overloading, the function is redefined by using either different types of arguments or a different

number of arguments. It is only through these differences compiler can differentiate between the

functions.

Function overloading is the ability to create multiple functions of the same name with

different parameters. When we call overloaded function ,it is called according to its parameter list.

Here in this program the overloaded functions are as follows.The advantage of Function

overloading is that it increases the readability of the program because you don't need to use
different

names for the same action.

int max(int a,int b);

int max(int a,int b,int c);

float max(float,float b);

int max(int a[20] );

Pseudo code:

1. Start

2. Define a class Overlaod_Area along with its data members

3. Define function area 4 times having different types of arguments such as


1. area(float r); returning 3.14 * r * r

2. area(int l,int b); returning l* b

3. area(double base,double height); returning 0.5* base *height

4. area(long side); returning side* side

4. In main function create a class objects

5. Call function area 4 times through objects and display the result of calculation of area

6. Stop

Conclusion:

I perform practical to calculate the area of a rectangle,triangle and circle using function overloading

//Name : Yash Patil

//PRN : 1941060

//S3 Batch

#include<iostream >

using namespace std;

int area(int,int);

float area(float);

float area(float,float);

int main()

Int I ,b ;

float r, bs, h;

cout<<”Enter length and breadth of rectangle : “ ;

cin>>l>>b;

cout<<Enter radius of circle : ”;

cin>>r;

cout<<Enter base and height of triangle : “;

cin>>bs>>h;

cout<<”\nArea of rectangle is ”<<area(l,b);


cout<<”\nArea of circle is”<<area(r);

cout<<"\nArea of triangle is:"<<area(bs,h);

int area(int l,int b)

return(l*b);

float area(float r)

return(3.14*r*r);

float area(float bs,float h)

return((bs*h)/2);

}
CO207U Object Oriented Programming Lab

Government College of Engineering, Jalgaon


(An Autonomous Institute of Government of Maharashtra)

PRN: 1941060 Name of the Student: Yash Patil


Class :S.Y. B.tech Semester :III DOP : 18/12/2020 DOC : 18/12/2020

Subject Teacher: Shrutika Mahajan Subject Coordinator:

Aim:-Create two classes DM and DB which stores the value of distances.Dm stores distances in

meters and centimeters and DB in feet and inches.Write c++ program that can read values for

the class object and add one object of DM with another object of DB.Use a friend function to

carry out the addition operation.The object that stores the result may be a DM object or DB

object,depending on the units in which the results are required.The display should in the form of

feet and inches or meters and centimetres depending on the object on display.

Compiler used: We used the g++ compiler to compile the C++ program.

Operating System used: Ubuntu

Theory:-

Friend function:

If a function is defined as a friend function in C++, then the protected and private data of a class

can be accessed using the function.By using the keyword friend compiler knows the given

function is a friend function.For accessing the data, the declaration of a friend function should be

done inside the body of a class starting with the keyword friend. for e.g.

class class_name

friend data_type function_name(argument/s); // syntax of friend function.

};

In the above declaration, the friend function is preceded by the keyword friend. The

function can be defined anywhere in the program like a normal C++ function. The function

definition does not use either the keyword friend or scope resolution operator.

Characteristics of a Friend function:

1. The function is not in the scope of the class to which it has been declared as a friend.
2. It cannot be called using the object as it is not in the scope of that class.

3. It can be invoked like a normal function without using the object.

4. It cannot access the member names directly and has to use an object name and dot

membership operator with the member name.

5. It can be declared either in the private or the public part.

Conversion Chart:-

millimete

r (mm))

centimeter

(cm)

meter

(m)

inch (in) feet (in)

1 mm 1 0.1 0.001 0.039370078740157 0.003280839895013

1cm 10 1 0.01 0.39370078740157 0.032808398950131

1m 1000 100 1 39.370078740157 3.2808398950131

1in 25.4 2.54 0.0254 1 0.083333333333333

1ft 304.8 30.48 0.3048 12 1

Pseudo code:-

1. Start

2. Declare class DBand define class DM

3. Declare data members and member functions of DM class

4. Define member functions for e.g. getDM(),dispDM() for DM class

5. Use friend function add() as a friend to both classes

6. Declare data members and member functions of DB class

7. Define member functions for e.g. getDB(),dispDB() for DB class

8. Define friend function add and convert centimeters,meters,feet and inches into meters

9. Create objects of both classes and perform addition operation by objects


10. Display result of addition

11. Stop

Conclusion:

I perform practical to Create two classes DM and DB which stores the value of distances.Dm stores
distances in meters and centimeters and DB in feet and inches.Write c++ program that can read
values for the class object and add one object of DM with another object of DB.Use a friend function
to carry out the addition operation.The object that stores the result may be a DM object or DB
object,depending on the units in which the results are required.The displayshould in the form of feet
and inches or meters and centimetres depending on the object on display.

//Name : Yash Patil

//PRN : 1941060

//S3 Batch

#include<iostream>

using namespace std;

class DB;

class DM

private:

int m;

double cm;

public:

void input()

cout<<"Enter distance in meter - centimeter : ";

cin>>m>>cm;

void show()

cout<<"\nDistance = "<<m<<" m & "<<cm<<" cm\n";

}
int getm()

return m;

double getcm()

return cm;

friend DM add(DM,DB);

};

class DB

private:

int ft;

double in;

public:

DB()

ft = in =0;

DB(DM dm)

double xin;

xin = (dm.getm()*100 + dm.getcm())*0.394;

ft = xin/12;

in = xin - (ft*12);

void input()

{
cout<<"Enter distance in feet - inches : ";

cin>>ft>>in;

void show()

cout<<"\nDistance = "<<ft<<" ft & "<<in<<" inches\n";

friend DM add(DM,DB);

};

DM add(DM mc,DB fi)

DM a;

double cm,in,xcm,xin;

cm = mc.m*100 + mc.cm;

in = fi.ft*12 + fi.in;

xcm = cm + in*2.54;

xin = in + cm*0.394;

a.m = xcm/100;

a.cm = xcm - (a.m*100);

return a;

int main()

DM a;
DB b;

a.input();

b.input();

cout<<"After adding : ";

DM c;

DB d;

c = add(a,b);

d = add(a,b);

c.show();

d.show();

return 0;

}
CO207U Object Oriented Programming Lab

Government College of Engineering, Jalgaon


(An Autonomous Institute of Government of Maharashtra)

PRN: 1941060 Name of the Student: Yash Patil

Class :S.Y. B.tech Semester :III DOP : 13/10/2020 DOC : 13/10/2020

Subject Teacher: Shrutika Mahajan Subject Coordinator:

Aim: Write a program to overload a unary operator using a member function.

Theory:

Operator overloading is a compile-time polymorphism in which the operator is

overloaded to provide the special meaning to the user-defined data type. Operator overloading is

used to overload or redefines most of the operators available in C++. It is used to perform the

operation on the user-defined data type. For example, C++ provides the ability to add the

variables of the user-defined data type that is applied to the built-in data types.The advantage of

Operators overloading is to perform different operations on the same operand.

Operator that cannot be overloaded are as follows:

● Scope operator (::)

● Sizeof

● member selector(.)

● member pointer selector(*)

● ternary operator(?:)

for e.g.

return_type class_name : : operator op(argument_list)

// body of the function.

Operator Overloading Restrictions:

● There are some restrictions that apply to operator overloading.

● We cannot alter the precedence of an operator.


● We cannot change the number of operands that an operator takes.

● Except for the function call, operator, operator functions cannot have default arguments.

● Finally, these operators cannot be overloaded: scope resolution operator (::), conditional

operator (:?), dot operator (.) and asterisk operator (*).

● Except for the = operator, operator functions are inherited by any derived class.

● However, a derived class is free to overload any operator (including those overloaded by

the base class) it chooses relative to itself.

Fibonacci series is written as follows-

0 1 1 2 3 5 8 13 21.....

The first and second term is 0 and 1 respectively and the subsequent term is the addition

of preceding two terms.

Hence, third = first + second

By this method, we can print the series upto n terms (which is user’s choice)

1. Start the program.

2. Declare class fibo with variables first, second and third.

3. Define constructor to initialize first as 0, the second as 1 and print first.

4. Define display function to print second.

5. Define unary operator overloading (++) to change the values of third, first and second.

6. Declare and define main function.

7. Input number of terms n.

8. Create object of fibo and call display function.

9. Define i=2 and check i less than n, if true goto STEP 10 else STEP 12.

10. Increment object and display.

11. Go to STEP 9 after incrementing i.

12.Stop.

Conclusion:

I perform practical to to overload a unary operator using the member function.


//Name : Yash Patil

//PRN : 1941060

//S3 Batch

#include<iostream>

using namespace std;

class Fibo {

private:

int a,b,c;

public:

Fibo ()

a=0;

b=1;

c=a+b;

void show()

cout<<c<<" ";

void operator++()

a=b;

b=c;

c=a+b;

};

int main()

int n,i;

Fibo f1;

cout<<"Please Enter the limit of the series: ";


cin>>n;

for(i=0;i<n;i++)

f1.show();

++f1;

return 0;

}
CO207U Object Oriented Programming Lab

Government College of Engineering, Jalgaon


(An Autonomous Institute of Government of Maharashtra)

PRN: 1941060 Name of the Student: Yash Patil

Class :S.Y. B.tech Semester :III DOP : 27/11/2020 DOC : 27/11/2020

Subject Teacher: Shrutika Mahajan Subject Coordinator:

Aim: Write a program to overload binary operator using friend function.

Compiler used: We used the g++ compiler to compile the C++ program.

Operating System used: Ubuntu

Theory:

The binary operators take two arguments and following are the examples of Binary

operators. We can use binary operators very frequently like addition (+) operator, subtraction (-)

operator and division (/) operator.We can use a friend function with built-in type data as the

left-hand operand and an object as the right-hand operand.As a rule, in overloading binary

operators,

1. the left-hand operand is used to invoke the operator function and

2. the right-hand operand is passed as an argument

The compiler invokes an appropriate constructor, initializes an object with no name and

returns the contents for copying into an object.Such an object is called a temporary object and

goes out of space as soon as the contents are assigned to another object. For e.g.

return complex((x+c.x), (y+c.y)); where complex is a class ‘c’ is an object of type complex

and x,y are the data variables

Overloading Binary Operators Using Friends:

1. Friend function requires two arguments to be explicitly passes to it.

2. Member function requires only one.

For e.g.

friend complex operator+(complex, complex);

complex operator+(complex a, complex b)


{

return complex((a.x + b.x),(a.y + b.y));

Pseudo Code:

1. Start

2. Declare the class complex.

3. Declare the variable and its member function accept() and display().

4. Declare a friend function like

a. friend Complex operator+(Complex c1, Complex c2);

5. Define the friend function +() to add two complex numbers and return object as an

argument.

6. Perform addition of two complex numbers.

7. In main function call the accept function twice and after performing addition on complex

numbers,display the result.

8. Stop the program.

Conclusion:

I perform practical to overload binary operator using friend function.

//Name : Yash Patil

//PRN : 1941060

//S3 Batch

#include<iostream>

using namespace std;

class complex

private:

float a,b;

public:

void accept(float x,float y)


{

a=x;

b=y;

void display()

cout<<a<<"+"<<b<<"i"<<endl;

friend complex operator +(complex,complex);

};

complex operator +(complex c1, complex c2)

complex c;

c.a=c1.a+c2.a;

c.b=c1.b+c2.b;

return c;

int main()

complex c1;

complex c2;

c1.accept(4.5,5.4);

c2.accept(6.2,2.1);

c1.display();

c2.display();

complex sum;

sum=c1+c2;

sum.display();

return 0;

}
CO207U Object Oriented Programming Lab

Government College of Engineering, Jalgaon


(An Autonomous Institute of Government of Maharashtra)

PRN: 1941060 Name of the Student: Yash Patil

Class :S.Y. B.tech Semester :III DOP :4/12/2020 DOC : 4/12/2020

Subject Teacher: Shrutika Mahajan Subject Coordinator:

Aim: Write a C++ program to demonstrate dynamic memory allocation.

Compiler used: We used the g++ compiler to compile the C++ program.

Operating System used: Ubuntu

Theory:

One use of dynamically allocated memory is to allocate memory of variable size which is

not possible with compiler allocated memory except variable length arrays.The most important

use is flexibility provided to programmers. We are free to allocate and deallocate memory

whenever we need and whenever we don’t need anymore. There are many cases where this

flexibility helps. Examples of such cases are Linked List, Tree, etc.

How is it different from memory allocated to normal variables?

For normal variables like “int a”, “char str[10]”, etc, memory is automatically allocated

and deallocated. For dynamically allocated memory like “int *p = new int[10]”, it is

programmers responsibility to deallocate memory when no longer needed. If programmer

doesn’t deallocate memory, it causes a memory leak (memory is not deallocated until program

terminates).

How is memory allocated/deallocated in C++?

C uses malloc() and calloc() function to allocate memory dynamically at run time and

uses free() function to free dynamically allocated memory. C++ supports these functions and

also has two operators new and delete that perform the task of allocating and freeing the memory

in a better and easier way.

The new operator denotes a request for memory allocation on the Heap. If sufficient memory is

available, new operator initializes the memory and returns the address of the newly allocated and

initialized memory to the pointer variable.


Syntax to use new operator: To allocate memory of any data type, the syntax is:

pointer-variable = new data-type;

Here, pointer-variable is the pointer of type data-type. Data-type could be any built-in data type

including array or any user defined data types including structure and class.

Example:

// Pointer initialized with NULL

// Then request memory for the variable

int *p = NULL;

p = new int; or

// Combine declaration of pointer

// and their assignment

int *p = new int;

Initialize memory: We can also initialize the memory using new operator:

pointer-variable = new data-type(value);

Example:

int *p = new int(25);

float *q = new float(75.25);

Allocate a block of memory: new operator is also used to allocate a block(an array) of memory

of type data-type.

pointer-variable = new data-type[size];

where size(a variable) specifies the number of elements in an array.

Example:

int *p = new int[10]

Dynamically allocates memory for 10 integers continuously of type int and returns pointer to the

first element of the sequence, which is assigned to p(a pointer). p[0] refers to first element, p[1]

refers to second element and so on.

Normal Array Declaration vs Using new

There is a difference between declaring a normal array and allocating a block of memory

using new. The most important difference is, normal arrays are deallocated by compiler (If array
is local, then deallocated when function returns or completes). However, dynamically allocated

arrays always remain there until either they are deallocated by the programmer or program

terminates.

What if enough memory is not available during runtime?

If enough memory is not available in the heap to allocate, the new request indicates

failure by throwing an exception of type std::bad_alloc, unless “nothrow” is used with the new

operator, in which case it returns a NULL pointer (scroll to section “Exception handling of new

operator” in this article). Therefore, it may be a good idea to check for the pointer variable

produced by new before using it program.

Pseudo Code:

1. Start

2. Declare one pointer variable and variables in a class.

3. Define member functions create() and insert() and max() function inside a class.

4. Create an array of a given size with new keyword.

5. Insert elements in an array one by one upto size of an array.

6. Find out the maximum number among all elements in an array.

7. Define a destructor and delete allocated size using delete keyword.

8. Call all functions in main function and print array along with maximum number.

9. Stop

Conclusion:

I perform practical exercises to demonstrate dynamic memory allocation.

//Name : Yash Patil

//PRN : 1941060

//S3 Batch

#include <iostream>

using namespace std;

class dyanamic

{
int *p;

int n,temp,maximum;

public:

void create()

p= new int[10];

void insert()

cout<<"Enter a nuber of elements in array"<<endl;

cin>>n;

cout<<"Isert elements inside the array"<<endl;

for(int i=0;i<n;i++)

cin>>p[i];

void max()

for(int i=0;i<n;i++)

if(p[i]>p[i+1])

temp=p[i];

p[i]=p[i+1];

p[i+1]=temp;

maximum=p[i+1];

}
cout<<"Maximum insert is "<<maximum<<endl;

~dyanamic()

delete []p;

};

int main()

dyanamic o;

o.create();

o.insert();

o.max();

return 0;

}
CO207U Object Oriented Programming Lab

Government College of Engineering, Jalgaon


(An Autonomous Institute of Government of Maharashtra)

PRN: 1941060 Name of the Student: Yash Patil

Class :S.Y. B.tech Semester :III DOP :1/1/2021 DOC : 1/1/2021

Subject Teacher: Shrutika Mahajan Subject Coordinator:

Aim: Write a program to calculate the total mark of a student using the concept of virtual base

class

Compiler used: We used the g++ compiler to compile the C++ program.

Operating System used: Ubuntu

Theory:

Virtual base class in C++

Virtual base classes are used in virtual inheritance in a way of preventing multiple

“instances” of a given class appearing in an inheritance hierarchy when using multiple

inheritances.

Need for Virtual Base Classes:

Consider the situation where we have one class A .This class is A is inherited by two

other classes B and C. Both these class are inherited into another in a new class D as shown in

figure 1 below.

As we can see from the figure that data members/function of class A are inherited twice

to class D. One through class B and second through class C. When any data / function member

of class A is accessed by an object of class D, ambiguity arises as to which data/function member

would be called? One inherited through B or the other inherited through C. This confuses

compiler and it displays error.To resolve this ambiguity when class A is inherited in both class B

and class C, it is declared as virtual base class by placing a keyword virtual as :

Syntax for Virtual Base Classes:

Syntax 1:

class B : virtual public A

{
};

Syntax 2:

class C : public virtual A

};

Virtual can be written before or after the public. Now only one copy of data/function

member will be copied to class C and class B and class A becomes the virtual base class.

Virtual base classes offer a way to save space and avoid ambiguities in class hierarchies that use

multiple inheritances. When a base class is specified as a virtual base, it can act as an indirect

base more than once without duplication of its data members. A single copy of its data members

is shared by all the base classes that use virtual base.

Pseudo Code:

1. Start

2. Create one class “Student” and define member function as getrno() and putrno() i.e. for

get roll number and displaying it.

3. Derive class “Test” along with its member functions getmarks() and purmarks() which is

for getting marks of students and displaying marks from “Student” and make “Student”

class as a virtual base class.

4. Again define class “Sports” with its member function getscore() and putscore() for

getting sports marks and displaying it and make “Student” class as a virtual base class for

“Sports” class.

5. Create one more class “Result” with its member functions display() for calculating all

subject marks with sports marks. Define a multiple inheritance relationships between

classes ,such as

Class Result:public Test,public Sports

6. Call all functions from class Student ,Test,Sports in display() function of class

“Result”.Calculate total marks from class''Test” and “Sport” in display() function.

7. In main function,create an object of a class Result and pass roll number,subject marks

and sports marks.

8. Stop
Conclusion:

I perform practical to calculate the total mark of a student using the concept of virtual base class

//Name : Yash Patil

//PRN : 1941060

//S3 Batch

#include <iostream>

using namespace std;

class Shape

public:

virtual void draw()

cout << "base class drawn" << endl;

};

class circle : public Shape

public:

void draw()

cout << "circle drawn" << endl;

};

class square : public Shape

{
public:

void draw()

cout << "square drawn" << endl;

};

class triangle : public Shape

public:

void draw()

cout << "triangle drawn" << endl;

};

int main()

Shape S;

circle c;

square s;

triangle t;

cout << "Calling base class function" << endl;

S.draw();

cout << "Calling derived class function" << endl;

Shape* p = &c;

p->draw();
p = &s;

p->draw();

p = &t;

p->draw();

}
CO207U Object Oriented Programming Lab

Government College of Engineering, Jalgaon


(An Autonomous Institute of Government of Maharashtra)

PRN: 1941060 Name of the Student: Yash Patil

Class :S.Y. B.tech Semester :III DOP :11/12/2020 DOC : 11/12/2020

Subject Teacher: Shrutika Mahajan Subject Coordinator:

Aim: Write a program to format output using different manipulators.

Compiler used: We used the g++ compiler to compile the C++ program.

Operating System used: Ubuntu

Theory:

Manipulator Functions:

Manipulator functions are special stream functions that change certain characteristics of

the input and output. They change the format flags and values for a stream. The main advantage

of using manipulator functions is that they facilitate that formatting of input and output

streams.The following are the list of standard manipulator used in a C++ program. To carry out

the operations of these manipulator functions in a user program, the header file input and output

manipulator <iomanip.h> must be included.

Predefined manipulators:Following are the standard manipulators normally used in the stream

classes:

1. endl

2. hex, dec, oct

3. setbase

4. setw

5. setfill

6. setprecision

7. ends

8. ws

9. flush

10. setiosflags
11. resetiosflags

(a) Endl: The endl is an output manipulator to generate a carriage return or line feed character.

The endl may be used several times in a C++ statement.

For example,

(1)

cout << “ a “ << endl << “b” << endl;

(2)

cout << “ a = “ << a << endl;

cout << “ b = “ << b << endl;

A program to display a message on two lines using the endl manipulator and the

corresponding output is given below.

/ / using endl manipulator

#include <iostream.h>

Void main (void)

cout << “ My name is Komputer “;

cout << endl;

cout << “ many greetings to you “;

Output of the above program

My name is Komputer

Many greetings to you

The endl is the same as the non-graphic character to generate line feed (\n).

(b) Setbase(): The setbase() manipulator is used to convert the base of one numeric value into

another base. Following are the common base converters in C++.

dec - decimal base (base = 10)

hex - hexadecimal base (base = 16)

oct - octal base (base = 8)

In addition to the base conversion facilities such as to bases dec, hex and oct, the

setbase() manipulator is also used to define the base of the numeral value of a variable. The
prototype of setbase() manipulator is defined in the iomanip.h header file and it should be

include in user program. The hex,dec,oct manipulators change the base of inserted or extracted

integral values. The original default for stream input and output is dec.

PROGRAM

A program to show the base of a numeric value of a variable using hex, oct and dec

manipulator functions.

/ / using dec, hex, oct manipulator

#include <iostream.h>

Void main (void)

int value;

cout << “ Enter number’ << endl;

cin >> value;

cout << “ Decimal base = “ << dec << value << endl;

cout << “ Hexadecimal base = “ << hex << value << endl;

cout << “ Octal base = “ << oct << value << endl;

Output of the above program

Enter number

10

Decimal base = 10

Hexadecimal base = a

Octal base = 12

(c) Setw (): The setw ( ) stands for the set width. The setw ( ) manipulator is used to specify the

minimum number of character positions on the output field a variable will consume.The general

format of the setw manipulator function is


setw( int w )

Which changes the field width to w, but only for the next insertion. The default field

width is 0.

For example,

cout << setw (1) << a << endl;

cout << setw (10) << a << endl;

Between the data variables in C++ space will not be inserted automatically by the

compiler. It is upto a programmer to introduce proper spaces among data while displaying onto

the screen.

PROGRAM

A program to display the data variables using setw manipulator functions.

/ /using setw manipulator

#include <iostream.h>

#include <iomanip.h>

void main (void)

int a,b;

a = 200;

b = 300;

cout << setw (5) << a << setw (5) << b << endl;

cout << setw (6) << a << setw (6) << b << endl;

cout << setw (7) << a << setw (7) << b << endl;

cout << setw (8) << a << setw (8) << b << endl;

Output of the above program

200 300

200 300

200 300

200 300
(d) Setfill(): The setfill ( ) manipulator function is used to specify a different character to fill the

unused field width of the value.The general syntax of the setfill ( ) manipulator is

setfill( char f)

which changes the fill character to f. The default fill character is a space.

For example,

setfill ( ‘ . ’ ) ; / / fill a dot ( . ) character

setfill ( ‘ * ’ ) / / fill a asterisk (*) character

Conclusion:-

I perform practical to format output using different manipulators.

PROGRAM

A program to illustrate how a character is filled in filled in the unused field width of the

value of the data variable.

/ /using setfill manipulator

#include <iostream.h>

#include <iomanip.h>

void main ( void)

int a,b;

a = 200;

b = 300;

cout << setfill ( ‘ * ’ );

cout << setw (5) << a << setw (5) << b << endl;

cout << setw (6) << a << setw (6) << b << endl;

cout << setw (7) << a << setw (7) << b << endl;

cout << setw (8) << a << setw (8) << b << endl;

Output of the above program


**200**300

***200***300

****200****300

*****200*****300

(e) Setprecision() :setprecision ( ) is used to control the number of digits of an output stream

display of a floating point value. The setprecision ( ) manipulator prototype is defined in the

header file <iomanip.h>The general syntax of the setprecision manipulator is

Setprecision (int p)

Which sets the precision for floating point insertions to p. The default precision is 6

PROGRAM

A program to use the setprecision manipulator function while displaying a floating point

value onto the screen.

/ /using setprecision manipulator

#include <iostream.h>

#include <iomanip.h>

void main (void)

float a,b,c;

a = 5;

b = 3;

c = a/b;

cout << setprecision (1) << c << endl;

cout << setprecision (2) << c << endl;

cout << setprecision (3) << c << endl;

cout << setprecision (4) << c << endl;

cout << setprecision (5) << c << endl;

cout << setprecision (6) << c << endl;

Output of the program


1.7

1.67

1.667

1.6667

1.66667

1.666667

(f) Ends: The ends is a manipulator used to attach a null terminating character (‘\0’) at the end

of a string. The ends manipulator takes no argument whenever it is invoked. This causes a null

character to the output.

PROGRAM

A program to show how a null character is inserted using ends manipulator while

displaying a string onto the screen.

/ /using ends manipulator

#include <iostream.h>

#include <iomanip.h>

Void main ( )

int number = 231;

cout << ‘ \ ” ’ << “ number = “ << number << ends;

cout << ‘ \ “ ‘ << endl;

Output of the above program

“ number = 123 “

(g) Ws:The manipulator function ws stands for white space. It is used to ignore the leading white

space that precedes the first field.

/ /using ws manipulator

#include <iostream.h>

#include <iomanip.h>

Void main ( )
{

char name [100]

cout << “ enter a line of text \n”;

cin >> ws;

cin >> name;

cout << “ typed text is = “ << name << endl;

Output of the program

enter a line of text

this is a text

typed text is = this

(h) Flush: The flush member function is used to cause the stream associated with the output to

be completed emptied. This argument function takes no input prameters whenever it is invoked.

For input on the screen, this is not necessary as all output is flushed automatically. However, in

the case of a disk file begin copied to another, it has to flush the output buffer prior to rewinding

the output file for continued use. The function flush ( ) does not have anything to do with

flushing the input buffer.

/ /using flush member function

#include <iostream.h>

#include <iomanip.h>

void main ( )

cout << “ My name is Komputer \n”;

cout << “ many greetings to you \n”;

cout . flush ( ) ;

The hex, dec, oct, ws, endl, ends and flush manipulators are defined in stream.h. The

other manipulators are defined in iomanip.h which must be included in any program that

employs them.
(i) Setiosflags and Resetiosflags: The setiosflags manipulator function is used to control

different input and output settings. The I/O stream maintains a collection of flag bits.The

setiosflags manipulator performs the same function as the setf function.he flags represented by

the set bits in f are set.The general syntax of the setiosflags is,

setiosflags ( long h)

The restiosflags manipulator performs the same function as that of the resetf function.

The flags represented by the set bits in f are reset.The general syntax of the resetiosflags is a

follows,

Resetiosflags (long f)

PROGRAM

A program to demonstrate how setiosflags is set while displaying the base of a numeral.

/ /using setiosflags of basefield

#include <iostream.h>

#include <iomanip.h>

void main (void)

int value;

cout << “ enter a number \n”;

cin >> value;

cout << setiosflags (ios : : showbase) ;

cout << setiosflags (ios : : dec) ;

cout << “ decimal = “ << value << endl;

cout << setiosflags (ios : : hex) ;

cout << hexadecimal = “ << value << endl ;

cout << setiosflags (ios : : oct) ;

cout << “ octal = “ << value << endl ;

Output of the above program


enter a number

10

decimal = 10

hexadecimal = 0xa

octal = 012

#include <iostream>

#include <istream>

#include <sstream>

#include <string>

#include <iomanip>

using namespace std;

int main()

istringstream str(" Programmer");

string line;

// Ignore all the whitespace in string

// str before the first word.

getline(str >> std::ws, line);

// you can also write str>>ws , After printing the output it will automatically

// write a new line in the output stream.

cout << line << endl;

// without flush, the output will be the same.

cout << "only a test" << flush;

// Use of ends Manipulator

cout << "\nA";


// NULL character will be added in the Output

cout << "B" << ends;

cout << "C" << endl;

// * Manipulator in <ios> *

double M = 100;

double N = 2001.5251;

double O = 201455.2646;

// We can use setbase(16) here instead of hex

// formatting

cout << hex << left << showbase << nouppercase;

// actual printed part

cout << (long long)M << endl;

// We can use dec here instead of setbase(10)

// formatting

cout << setbase(10) << right << setw(15)

<< setfill('_') << showpos

<< fixed << setprecision(2);

// actual printed part

cout << N << endl;

// formatting

cout << scientific << uppercase

<< noshowpos << setprecision(9);


// actual printed part

cout << O << endl;

return 0;

}
CO207U Object Oriented Programming Lab

Government College of Engineering, Jalgaon


(An Autonomous Institute of Government of Maharashtra)

PRN: 1941060 Name of the Student: Yash Patil

Class :S.Y. B.tech Semester :III DOP :1/1/2021 DOC : 1/1/2021

Subject Teacher: Shrutika Mahajan Subject Coordinator:

Aim: Consider a class Number having a function to accept and print a roll_no., a class Marks

having function to accept and print marks of two subjects; and a class Student having function to

display total of two subjects. Write a C++ program to calculate total of 2 subjects for a student

using multilevel inheritance.

Compiler used: We used the g++ compiler to compile the C++ program.

Operating System used: Ubuntu

Theory:

Inheritance:

In C++, inheritance is a process in which one object acquires all the properties and

behaviors of its parent object automatically. In such a way, you can reuse, extend or modify the

attributes and behaviors which are defined in other class.In C++, the class which inherits the

members of another class is called derived class and the class whose members are inherited is

called base class. The derived class is the specialized class for the base class.you can reuse the

members of your parent class. So, there is no need to define the member again. So less code is

required in the class.C++ supports five types of inheritance:

1. Single inheritance

2. Multiple inheritance

3. Hierarchical inheritance

4. Multilevel inheritance

5. Hybrid inheritance

C++ Multilevel Inheritance:

When one class inherits another class which is further inherited by another class, it is

known as multi level inheritance in C++. Inheritance is transitive so the last derived class
acquires all the members of all its base classes

Figure1. Multilevel Inheritance

For example:

class A // base class

...........

};

class B : acess_specifier A // derived class

...........

};

class C : access_specifier B // derived from derived class B

...........

};

Pseudo Code:

1. Start

2. Define a class “Number” which takes roll number in acceptt_rno() function and

print_rno() to print roll number.

3. Define class “Marks” which is derived from class number.Define member function

accept_marks() to get marks of subjects and print_marks to print it.

4. Define class “Student” which is again derived from class “Marks” having member

functions getdata() and dispaly_data() for calculating total marks and and display total

marks with roll number respectively.

5. In main function call member functions of all classes through an object of

“Student”class.This will show multilevel inheritance relationship between classes such as

Number----------->Marks------------->Student

6. Stop

Conclusion:
I perform practical to Consider a class Number having a function to accept and print a
roll_no., a class Marks having function to accept and print marks of two subjects; and a class Student
having function to display total of two subjects. Write a C++ program to calculate total of 2 subjects
for a student using multilevel inheritance.

//Name : Yash Patil

//PRN : 1941060

//S3 Batch

#include<iostream>

using namespace std;

class number

public:

int rno;

void accept_rno()

cout<<"Enter a roll no."<<endl;

cin>>rno;

void print_rno()

cout<<"Roll no :"<<rno<<endl;

};

class marks:public number

public:

int mark1,mark2;
void accept_marks()

cout<<"Enter marks of two subjects"<<endl;

cin>>mark1>>mark2;

void print_marks()

cout<<"Marks obtained in subject 1:"<<mark1<<endl;

cout<<"Marks obtained in subject 2:"<<mark2<<endl;

};

class student: public marks

public:

int total;

void getdata()

total=mark1+mark2;

void put_data()

cout<<endl;

cout<<"Roll no:"<<rno<<endl;

cout<<"total marks obtained:"<<total<<endl;

};

int main()

student s;

s.accept_rno();

s.print_rno();
s.accept_marks();

s.print_marks();

s.getdata();

s.put_data();

return 0;

}
CO207U Object Oriented Programming Lab

Government College of Engineering, Jalgaon


(An Autonomous Institute of Government of Maharashtra)

PRN: 1941060 Name of the Student: Yash Patil

Class :S.Y. B.tech Semester :III DOP :11/12/2020 DOC : 11/12/2020

Subject Teacher: Shrutika Mahajan Subject Coordinator:

Aim:Write a C++ program to perform matrix operation using Templates.

Compiler used: We used the g++ compiler to compile the C++ program.

Operating System used: Ubuntu

Theory:

C++ Templates

A C++ template is a powerful feature added to C++. It allows you to define the generic classes

and generic functions and thus provides support for generic programming. Generic programming

is a technique where generic types are used as parameters in algorithms so that they can work for

a variety of data types.

Templates can be represented in two ways:

● Function templates

● Class templates

Function Templates:

We can define a template for a function. For example, if we have an add() function, we can

create versions of the add function for adding the int, float or double type values.

Class Template:

We can define a template for a class. For example, a class template can be created for the array

class that can accept the array of various types such as int array, float array or double array.

Function Template

● Generic functions use the concept of a function template. Generic functions define a set

of operations that can be applied to the various types of data.

● The type of the data that the function will operate on depends on the type of the data

passed as a parameter.
● For example, Quick sorting algorithm is implemented using a generic function, it can be

implemented to an array of integers or array of floats.

● A Generic function is created by using the keyword template. The template defines what

function will do.

Syntax of Function Template

1. template < class Ttype> ret_type func_name(parameter_list)

2. {

3. // body of function.

4. }

Where Ttype: It is a placeholder name for a data type used by the function. It is used within the

function definition. It is only a placeholder that the compiler will automatically replace this

placeholder with the actual data type.

class: A class keyword is used to specify a generic type in a template declaration.

Class Template:

Class Template can also be defined similarly to the Function Template. When a class uses the

concept of Template, then the class is known as generic class.

Syntax

1. template<class Ttype>

2. class class_name

3. {

4. .

5. .

6. }

Ttype is a placeholder name which will be determined when the class is instantiated. We can

define more than one generic data type using a comma-separated list. The Ttype can be used

inside the class body.

Now, we create an instance of a class

1. class_name<type> ob;

where class_name: It is the name of the class.


type: It is the type of the data that the class is operating on.

ob: It is the name of the object

Pseudo Code:

1. Start

2. Define a function template add/sub/mul with parameters as per size of a matrix.

3. Perform operation on matrices according to size of matrix

a. sum[i][j]=a[i][j] +b[i][j] for adding two matrices

b. sub [i][j]=a[i][j] -b[i][j] for subtracting matrices

c. for(i = 0; i < r1; ++i)

d. for(j = 0; j < c2; ++j)

e. {

f. mult[i][j]=0;

g. }

h.

i. // Multiplying matrix a and b and storing in array mult.

j. for(i = 0; i < r1; ++i)

k. for(j = 0; j < c2; ++j)

l. for(k = 0; k < c1; ++k)

m. {

n. mult[i][j] += a[i][k] * b[k][j];

o. }

p. In main function enter size of matrices and operation wanted to perform.

q. Stop

Conclusion:

I perform Practical for matrix operation using Templates.

//Name : Yash Patil

//PRN : 1941060

//S3 Batch

#include<iostream>
using namespace std;

const int r=2,c=2;

template<class T>

class matrix

T m[r][c];

public:

void get_value()

for(int i=0;i<r;i++)

for(int j=0;j<c;j++)

cout<<"\n M["<<i<<"]["<<j<<"] = ";

cin>>m[i][j];

void operator +(matrix ob)

T p[r][c];

for(int i=0;i<r;i++)

for(int j=0;j<c;j++)

p[i][j]=m[i][j]+ob.m[i][j];
cout<<" "<<p[i][j]<<" ";

cout<<"\n";

void operator -(matrix ob)

T p[r][c];

for(int i=0;i<r;i++)

for(int j=0;j<c;j++)

p[i][j]=m[i][j]-ob.m[i][j];

cout<<" "<<p[i][j]<<" ";

cout<<"\n";

void operator *(matrix ob)

T p[r][c];

for(int i=0;i<r;i++)

for(int j=0;j<c;j++)

p[i][j]=0;

for(int k=0;k<c;k++)
{

p[i][j]+=(m[i][k] * ob.m[k][j]);

for(int i=0;i<r;i++)

for(int j=0;j<c;j++)

cout<<" "<<p[i][j]<<" ";

cout<<"\n";

void transpose()

T p[r][c];

for(int i=0;i<r;i++)

for(int j=0;j<c;j++)

p[j][i]=m[i][j];

}for(int i=0;i<r;i++)

for(int j=0;j<c;j++)

{
cout<<" "<<p[i][j]<<" ";

cout<<"\n";

void display()

for(int i=0;i<r;i++)

for(int j=0;j<c;j++)

cout<<" "<<m[i][j]<<" ";

cout<<"\n";

cout<<"\n\n";

};

int main()

matrix<int> m1,m2;

int ch;

cout<<"\n Enter Elements of Matrix A\n";

m1.get_value();
cout<<"\n Enter Elements of Matrix B\n";

m2.get_value();

while(1)

system("cls");

cout<<"\n MATRIX OPERATIONS\n";

cout<<"\n 1. Sum";

cout<<"\n 2. Difference";

cout<<"\n 3. Product";

cout<<"\n 4. Transpose";

cout<<"\n 5. Display";

cout<<"\n 0. EXIT\n";

cout<<"\n Enter your choice: ";

cin>>ch;

switch(ch)

case 1: cout<<"\n Matrices Sum \n";

m1 + m2;

break;

case 2: cout<<"\n Matrices Subtraction \n";

m1-m2;

break;

case 3: cout<<"\n Matrices Product \n";

m1*m2;

break;

case 4: cout<<"\n MATRIX A\n";

m1.display();

cout<<"\n Transposed Matrix\n";

m1.transpose();
cout<<"\n MATRIX B\n";

m2.display();

cout<<"\n Transposed Matrix\n";

m2.transpose();

break;

case 5: cout<<"\n\n MATRIX A\n";

m1.display();

cout<<"\n MATRIX B\n";

m2.display();

break;

case 0: exit(0);

default: cout<<"\n Invalid choice";

system("pause");

};

}
CO207U Object Oriented Programming Lab

Government College of Engineering, Jalgaon


(An Autonomous Institute of Government of Maharashtra)

PRN: 1941060 Name of the Student: Yash Patil

Class :S.Y. B.tech Semester :III DOP :01/01/2021 DOC : 01/01/2021

Subject Teacher: Shrutika Mahajan Subject Coordinator:

Aim:Generate record for student containing name, age, weight, height, blood group, phone

number and address. Print and store the record in the file.

Compiler used: We used the g++ compiler to compile the C++ program.

Operating System used: Ubuntu

Theory:

In C++, files are mainly dealt by using three classes fstream, ifstream, ofstream available in

fstream header file.

a. ofstream: Stream class to write on files

b. ifstream: Stream class to read from files

c. fstream: Stream class to both read and write from/to files.

Now the first step to open the particular file for read or write operation. We can open file by

1. passing file name in constructor at the time of object creation

2. using the open method

Default Open Modes :

Sr Member Constants Stands for Access


No.
1 In* input File open for reading: the internal stream buffer
supports input operations.
2 out output File open for writing: the internal stream buffer
supports output operations.
3 binary bianary Operations are performed in binary mode rather
than text.
4 ate at end The output position starts at the end of the file.
5 app append All output operations happen at the end of the
file, appending to its existing contents.
6 trunc truncate Any contents that existed in the file before it is
open are discarded.

Default Open Modes :

Sr No. Name Form


1 Ifstream ios:in
2 Ofstream ios:out
3 Fstream Ios:in |ios:out

Opening a File

A file must be opened before you can read from it or write to it. Either ofstream or

fstream object may be used to open a file for writing. And ifstream object is used to open a file

for reading purpose only.Following is the standard syntax for open() function, which is a

member of fstream, ifstream, and ofstream objects.

void open(const char *filename, ios::openmode mode);

Here, the first argument specifies the name and location of the file to be opened and the

second argument of the open() member function defines the mode in which the file should be

opened.

Closing a File

When a C++ program terminates it automatically flushes all the streams, release all the

allocated memory and close all the opened files. But it is always a good practice that a

programmer should close all the opened files before program termination.Following is the

standard syntax for close() function, which is a member of fstream, ifstream, and ofstream

objects.

void close();

Writing to a File

While doing C++ programming, you write information to a file from your program using

the stream insertion operator (<<) just as you use that operator to output information to the

screen. The only difference is that you use an ofstream or fstream object instead of the cout

object.
Reading from a File

You read information from a file into your program using the stream extraction operator

(>>) just as you use that operator to input information from the keyboard. The only difference is

that you use an ifstream or fstream object instead of the cin object.

File Position Pointers

Both istream and ostream provide member functions for repositioning the file-position

pointer. These member functions are seekg ("seek get") for istream and seekp ("seek put") for

ostream.

The argument to seekg and seekp normally is a long integer. A second argument can be

specified to indicate the seek direction. The seek direction can be ios::beg (the default) for

positioning relative to the beginning of a stream, ios::cur for positioning relative to the current

position in a stream or ios::end for positioning relative to the end of a stream.

Pseudo Code:

1. Start

2. Define a class Student with getdata() and disp() functions to get

prn,name,address,age,blood group,weight and height.

3. In main() function

a. Create an object of a class Student.

b. Create objects of file input and output streams.

c. Open file using output stream.

d. Write data in file and close it.

e. Again reopen it and read data in file.

f. Call disp() function to print data from file on output screen.

4. Stop

Conclusion:

I perform practical to Generate record for student containing name, age, weight, height , blood
group, phone number and address. Print and store the record in the file.

//Name : Yash Patil


//PRN : 1941060

// S3 Batch

#include<iostream>

#include<fstream>

#include<string>

Using namespace std;

Class Student

String name;

Int age;

Float weight;

Float height;

String bloodGroph;

Int phone;

String address;

Public:

Void getData(); // get student data from user

Void displayData(); // display data

};

Void Student :: getData() {

Cout <<”\nEnter Name : “<<endl;

Cin.ignore();

Getline(cin, name); //reads embedded blanks

// cin>>name;

Cout << “\nEnter Age : “<<endl;

Cin >>age;
Cout << “\nEnter Weight[KG] : “<<endl;

Cin >> weight;

Cout << “\nEnter Height[Cms] : “<<endl;

Cin >> height;

Cout << “\nEnter BloodGroup : “<<endl;

Cin.ignore();

Getline(cin, bloodGroph); //reads embedded blanks

Cout << “\nEnter Phone Number : “<<endl;

Cin>>phone;

Cout << “\nEnter Your Address : “<<endl;

// getline(cin, address, ‘$’);// reads multile line

Cin.ignore();

Getline(cin, address);

Void Student :: displayData() {

Cout<<”\nDisplaying Student formation : \n”;

Cout <<”NAME : “ << name << endl;

Cout <<”AGE : “ << age << endl;

Cout<<”WEIGHT : “<<weight <<endl;

Cout<<”HEIGHT: “<< height<<endl;

Cout<<”Blood Group : “<<bloodGroph <<endl;

Cout<<”PHONE NUMBER : “<< phone<<endl;

Cout<<”ADDRESS : “<< address<<endl;


}

Int main()

Student s[3];

Int n;

Cout<<”Enter No of Students : “<<endl;

Cin>>n;

S[n];

Fstream file;

Int I;

File.open(“./Student.txt”, ios :: out); // open file for writing

Cout << “\nWriting Student information to the file :- “ << endl;

Cout << “\nEnter “<<n<< “ students Details to the File :- “ << endl;

For (I = 0; I < n; i++){

S[i].getData();

// write the object to a file

File.write((char *)&s[i], sizeof(s[i]));

File.close(); // close the file

File.open(“./Student.txt”, ios :: in); // open file for reading

Cout << “\nReading Student information to the file :- “ << endl;

For (I = 0; I < n; i++){

// read an object from a file


File.read((char *)&s[i], sizeof(s[i]));

S[i].displayData();

File.close();

Return 0;

………………….

………………….

Output :-

Enter No of Students :

Writing Student information to the file :-

Enter 1 students Details to the File :-

Enter Name :

Yash Patil

Enter Age :

20

Enter Weight[KG] :

61

Enter Height[Cms] :

178
Enter BloodGroup :

O+

Enter Phone Number :

9669297677

Enter Your Address : indore

Reading Student information to the file :-

Displaying Student formation :

NAME : Yash Patil

AGE : 20

WEIGHT : 61

HEIGHT: 178

Blood Group : O+

PHONE NUMBER : 9669297677

ADDRESS :indore

[Process completed – press Enter]

CO207U Object Oriented Programming Lab

Government College of Engineering, Jalgaon


(An Autonomous Institute of Government of Maharashtra)

PRN: 1941060 Name of the Student: Yash Patil

Class :S.Y. B.tech Semester :III DOP :04/12/2020 DOC : 04/12/2020

Subject Teacher: Shrutika Mahajan Subject Coordinator:

Aim: Create a simple "Shape" hierarchy. A base class called Shape and derived classes called

Circle, Square and Triangle. In the base class write a virtual function "draw" and override this in
derived classes.

Theory:

Hierarchical Inheritance:

In hierarchical inheritance several classes can be derived from a single base class.

Syntax:

class base-class-name

Data members

Member functions

};

class derived-class-name1 : visibility mode base-class-name

Data members

Member functions

};

class derived-class-name2: visibility mode base-class-name

Data members

Member functions

};

Virtual Function:

Virtual means existing in appearance but not in reality. When virtual functions are used, a program

that appears to be calling a function of one class may in reality be calling a function of a different

class.Through this program we get the area of Circle ,Square and Triangle by using virtual member

function in base class.We have created the pointer of base class and stored the address of derived

class object and then have called the member functions.

Pseudo Code:.

1. Start the program.

2. Create a base class shape.

3. Declare it's variables and member functions and Declare it as virtual.

4. Derive class circle from base class.


5. Derive class square from base class.

6. Define the variables and member functions.

7. Construct a derived class from base class.

8. Define the variables and member functions in derived class.

9. Create objects of each derived classes.

10. Create pointer to base class.

11. Store address of derived class object to the base class pointer and call them.

12. Stop

Conclusion:

I perform practical tasks to Create a simple “Shape” hierarchy. A base class called Shape and derived
classes called Circle, Square and Triangle. In the base class write a virtual function “draw” and
override this in derived classes.

//Name : Yash Patil

//PRN : 1941060

S3 Batch

#include<iostream>

using namespace std;

class student

public:

int Roll_no;

void getrno()

cout<<"Enter Roll No :"<<endl;

cin>>Roll_no;

void putrno()

cout<<"Roll No :"<<Roll_no<<endl;

};
class test: virtual student

public:

int n,marks[10];

void getmark()

cout<<"Enter no. of subjects:"<<endl;

cin>>n;

cout<<"Enter marks:"<<endl;

for(int i=0;i<n;i++)

cin>>marks[i];

void putmark()

cout<<"marks obtained "<<endl;

for(int i=0;i<n;i++)

cout<<i<<":"<<marks[i]<<endl;

};

class sports: virtual student

public:

int m,score[10];

void getscore()

cout<<"Enter no of sports:"<<endl;

cin>>m;
cout<<"Enter marks:"<<endl;

for(int j=0;j<m;j++)

cin>>score[j];

void putscore ()

cout<<"scores:"<<endl;

for (int j=0;j<m;j++)

cout<<j+1<<"."<<score [j]<<endl;

};

class result: public test, public sports

public:

int total_marks=0;

int total_score=0;

void total()

for(int k=0;k<n;k++)

total_marks=total_marks+marks[k];

cout<<"total marks ="<<total_marks<<endl;

for (int i=0;i<m;i++)

total_score=total_score+score[i];

}
cout<<"total score ="<<total_score;

};

int main()

result r;

student s;

s.getrno();

s.putrno();

r.getmark();

r.putmark();

r.getscore();

r.putscore();

r.total();

return 0;

OUTPUT:-
Extra practicals experiments:file handling 2(grp B-5)

#include<iostream>

#include<fstream>

using namespace std;

class Person

string name;

string occupation;

int age;

public:

void getdata()

cout<<"Name: ";

cin>>name;

cout<<"Age : ";

cin>>age;

cout<<"Occupation : ";

cin>>occupation;

void putdata()

cout<<"Name: "<<name<<endl<<"Age : "<<age<<endl<<"Occupation : "<<occupation<<endl;

string getName(){

return this->name;

}
}per1;

int main()

fstream fio("marks.dat",ios::app|ios::in|ios::out|ios::binary);

char ans='y';

while(ans=='y' || ans=='Y')

per1.getdata();

fio.write((char *)&per1, sizeof(per1));

cout<<"Record added to the file\n";

cout<<"\nWant to enter more ? (y/n)..";

cin>>ans;

string name;

long pos;

char found='f';

cout<<"Enter Name of Person to be search for: ";

cin>>name;

fio.seekg(0);

while(!fio.eof())

pos=fio.tellg();

fio.read((char *)&per1, sizeof(per1));

if(per1.getName() == name)

{
per1.putdata();

fio.seekg(pos);

found='t';

break;

if(found=='f')

cout<<"\nRecord not found in the file..!!\n";

cout<<"Press any key to exit...\n";

exit(1);

fio.close();

return 0;

OUTPUT :
Extra practicals experiments: calculating
perimeter(grpA_7)

#include <iostream>

using namespace std;

class shape{

public:

int length;

int width;

};

class Area : virtual public shape{

public:

int Calculate_Area(){
return length*width;

};

class Perimeter : virtual public shape{

public:

int Calculate_Perimeter(){

return 2*(length+width);

};

class Rectangle : public Area, public Perimeter{

public:

void getDimention(){

cout<<"Enter Length & Width :";cin>>length>>width;

void Calculate_Area_Perimeter(){

cout<<"Area of Rectangle is :"<<Calculate_Area()<<endl;

cout<<"Perimeter of Rectangle is :"<<Calculate_Perimeter()<<endl;

};

int main(){

Rectangle rectangle;

rectangle.getDimention();

cout<<"Area of rectangle is :"<<rectangle.Calculate_Area()<<endl;

cout<<"Perimeter of rectangle is :"<<rectangle.Calculate_Perimeter()<<endl;

return 0;

OUTPUT:-

Enter length & Width :12

44

Area of rectangle is :528


Perimeter of rectangle is:112

[Process completed -press Enter]

Experiment :Stack and queue operations

Stack :

#include <iostream>

#include <stack>

using namespace std;

int main() {

stack<int> st;

st.push(10);

st.push(20);

st.push(30);

st.push(40);

st.pop();

st.pop();
while (!st.empty()) {

cout << ' ' << st.top();

cout<<" pop:";

st.pop();

cout<<"size :"<<st.size()<<endl;

OUTPUT :
Queue :

#include <iostream>

#include <cstdlib>

using namespace std;

// define default capacity of the queue

#define SIZE 10

// Class for queue

class queue

int *arr; // array to store queue elements

int capacity; // maximum capacity of the queue

int front; // front points to front element in the queue (if any)

int rear; // rear points to last element in the queue

int count; // current size of the queue

public:

queue(int size = SIZE); // constructor

~queue(); // destructor

void dequeue();

void enqueue(int x);

int peek();

int size();

bool isEmpty();

bool isFull();
};

// Constructor to initialize queue

queue::queue(int size)

arr = new int[size];

capacity = size;

front = 0;

rear = -1;

count = 0;

// Destructor to free memory allocated to the queue

queue::~queue()

delete[] arr;

// Utility function to remove front element from the queue

void queue::dequeue()

// check for queue underflow

if (isEmpty())

cout << "UnderFlow\nProgram Terminated\n";

exit(EXIT_FAILURE);

cout << "Removing " << arr[front] << '\n';

front = (front + 1) % capacity;


count--;

// Utility function to add an item to the queue

void queue::enqueue(int item)

// check for queue overflow

if (isFull())

cout << "OverFlow\nProgram Terminated\n";

exit(EXIT_FAILURE);

cout << "Inserting " << item << '\n';

rear = (rear + 1) % capacity;

arr[rear] = item;

count++;

// Utility function to return front element in the queue

int queue::peek()

if (isEmpty())

cout << "UnderFlow\nProgram Terminated\n";

exit(EXIT_FAILURE);

return arr[front];

}
// Utility function to return the size of the queue

int queue::size()

return count;

// Utility function to check if the queue is empty or not

bool queue::isEmpty()

return (size() == 0);

// Utility function to check if the queue is full or not

bool queue::isFull()

return (size() == capacity);

int main()

// create a queue of capacity 5

queue q(5);

q.enqueue(1);

q.enqueue(2);

q.enqueue(3);

cout << "Front element is: " << q.peek() << endl;

q.dequeue();

q.enqueue(4);
cout << "Queue size is " << q.size() << endl;

q.dequeue();

q.dequeue();

q.dequeue();

if (q.isEmpty())

cout << "Queue Is Empty\n";

else

cout << "Queue Is Not Empty\n";

return 0;

OUTPUT :

Extra Practice3_ student class :


#include <iostream>

using namespace std;

class Student{

string student_name;

int marks[3];

int total_marks;

float percentage;

public:

Student(string name,int arr_marks[]){

student_name = name;

for(int i=0;i<3;i++){

marks[i] = arr_marks[i];

total_marks = 0;

void Compute(){

total_marks = 0;

for(int i=0;i<3;i++){

total_marks = total_marks + marks[i];

percentage = total_marks/3;

void display(){

cout<<"Name : "<<student_name<<endl;

cout<<"Total marks : "<<total_marks<<endl;


cout<<"Percentage : "<<percentage<<endl;

};

int main(){

int marks[3];

string name;

cout<<"Enter Name : ";cin>>name;

cout<<"Enter Marks: ";cin>>marks[0]>>marks[1]>>marks[2];

Student yash(name,marks);

yash.Compute();

yash.display();

return 0;

OUTPUT :
Extra Practice 2.Overloading = operator
#include <iostream>

using namespace std;

class Point {

private:

int x;

int y;

public:

Point() {

x = 0;

y = 0;

Point(int a, int b) {

x = a;

y = b;

void operator = (const Point &P ) {

x = P.x;

y = P.y;

void showPoint() {

cout<<"Point is : "<<"("<<x<<","<<y<<")"<<endl;

}
};

int main() {

Point A(17, 8), B(7, 17);

cout<<"First : ";

A.showPoint();

cout << "Second :";

B.showPoint();

A = B; // use assignment operator

cout << "First :";

A.showPoint();

return 0;

OUTPUT :
Practice1_friend function n friend class

#include <iostream>

using namespace std;

class Distance

{ private:

int meter;

public:

Distance()

meter=0;

void display()

cout<<"value of meter is: "<<meter<<endl;

//prototype

friend void frfunc(Distance &d);

};

void frfunc(Distance &d)


{

d.meter = d.meter +5;

int main()

Distance d1;

d1.display();

//friend function call

frfunc(d1); //pass by refernce

cout<<endl<<endl;

d1.display();

return 0;

OUTPUT :
PROJECT REPORT
On

Student Report card Handling System


(CSE III Semester Mini project)
2020-2021

Submitted by:
1941060 Yash Patil

1941062 Aditya Zanzad

TEACHER NAME:
Shrutika Mahajan HOD: D.V. Chaudhary
TABLE OF CONTENTS

CHAPTER NO. TITLE PAGE NO.

1 INTRODUCTION 1

1.1 About Project 1

1.2 Requirement of Project 1

1.2.1 Hardware Requirement 1

1.2.2 Software Requirement 1

2 Modules of Project 2

2.1 Create Record 2

2.2 Display Class Result 2

2.3 Display student Result 2

2.4 Modifying Records 2

2.5 Deleting Records 2

2.6 Class Result 2

3 Any other relevant information 3

3.1 E-R Diagram 3

3.2 Data Flow Diagram 3

4 Snapshots Of Project 4

4.1 First Page 4

4.2 Main Menu 4

4.3 Result Menu 5

4.4 Class Result 5

4.5 Entry Edit Menu 6

4.6 Create New Record 6

4.7 Modifying Students Record 7

5 Conclusion 8

Appendix(Code) 9
REFERENCE 21

CHAPTER 1

INTRODUCTION

1.1 About Project

This project is for the practical implementation of Student Report card of any class. This program
follows modular approach for different task to make the code easy to understand. From this project
we can perform operations like create , view , edit , etc.

This program is written in C language.


1.2 Requirement of Project

1.2.1 Hardware Requirement

Standard Input Devices- Keyboard ,mouse.

Standard Output Devices- Display,Speakers.

1.2.2 Software Requirement

Any Operating System(Windows , Linux)

A C IDE

CHAPTER 2

MODULES OF PROJECT

1-Create Record(write())

In this module we can create record of any student by his unique roll no. and name with his\her
respective marks. This module also find grades and percentage automatically.

2-Display Class Result(display())

This module can show us all the students records present in the data file.

3-Display Student Result(display())

This module can show us the record of any individual student present in the data file via his/her roll
no.

4-Modifying Records(modify())

This module can modify all records of a student just by entering his/her existing roll no.

5-Deleting Records(del())

This module can delete all records of a student just by entering his/her existing roll no.
6-Class Result(classr())

This module can show us all the records of the whole class present in the data file .

Its can show us all the marks with names and grades.

CHAPTER 3

Any other relevant information

3.1 E-R Diagram

3.2 Data Flow Diagram


CHAPTER 4

SNAPSHOTS OF PROJECTS

4.1 First Page

4.2 Main Menu


4.3 Result Menu

4.4 Class Result

4.5 Entry Edit menu


4.6 Create New Record

4.7 Modifying Students Report


CHAPTER 5

CONCLUSION

At the end it can be said that this project is highly efficient to store and process the marks by schools
and colleges.

It consumes a tiny amount of storage and easy to use.

Its Simple User Interface makes this project even more convenient in the real world to use.

It is based on the concepts of file Handling so we can easily transfer the file to any other pc at ease.
APPENDIX (CODE)

#include<conio.h>

#include<stdio.h>

#include<process.h>

#include<windows.h>

FILE *fptr;

struct student

int rollno;

char name[50];

int p,c,m,e,cs;

float per;

char grade;

}stud;

void write()

{
fptr=fopen("F:\\test\\student.dat","ab");

printf("\nPlease Enter The New Details of student \n");

printf(" roll number of student ");

scanf("%d",&stud.rollno);

fflush(stdin);

printf("\n Name of student ");

gets(stud.name);

printf(" marks in physics out of 100 : ");

scanf("%d",&stud.p);

printf(" marks in chemistry out of 100 : ");

scanf("%d",&stud.c);

printf(" marks in maths out of 100 : ");

scanf("%d",&stud.m);

printf(" marks in english out of 100 : ");

scanf("%d",&stud.e);

printf(" marks in computer science out of 100 : ");

scanf("%d",&stud.cs);

stud.per=(float)(stud.p+stud.c+stud.m+stud.e+stud.cs)/5.0;

if(stud.per>=60)

stud.grade='A';

else if(stud.per>=50 &&stud.per<60)

stud.grade='B';

else if(stud.per>=33 &&stud.per<50)

stud.grade='C';

else

stud.grade='F';

fwrite(&stud,sizeof(stud),1,fptr);

fclose(fptr);

printf("\n\nStudent Record Has Been Created ");

getch();

}
void display()

system("cls");

printf("\n\n\n\t\tDISPLAY ALL RECORD !!!\n\n");

fptr=fopen("F:\\test\\student.dat","rb");

while((fread(&stud,sizeof(stud),1,fptr))>0)

printf("\nRoll Number of Student : %d",stud.rollno);

printf("\nName of student : %s",stud.name);

printf("\nMarks in Physics : %d",stud.p);

printf("\nMarks in Chemistry : %d",stud.c);

printf("\nMarks in Maths : %d",stud.m);

printf("\nMarks in English : %d",stud.e);

printf("\nMarks in Computer Science : %d",stud.cs);

printf("\nPercentage of student is : %.2f",stud.per);

printf("\nGrade of student is : %c",stud.grade);

printf("\n\n====================================\n");

getch();

fclose(fptr);

getch();

void display1(int n)

int flag=0;
fptr=fopen("F:\\test\\student.dat","rb");

while((fread(&stud,sizeof(stud),1,fptr))>0)

if(stud.rollno==n)

system("cls");

printf("\nRoll number of student : %d",stud.rollno);

printf("\nName of student : %s",stud.name);

printf("\nMarks in Physics : %d",stud.p);

printf("\nMarks in Chemistry : %d",stud.c);

printf("\nMarks in Maths : %d",stud.m);

printf("\nMarks in English : %d",stud.e);

printf("\nMarks in Computer Science : %d",stud.cs);

printf("\nPercentage of student is : %.2f",stud.per);

printf("\nGrade of student is : %c",stud.grade);

flag=1;

fclose(fptr);

if(flag==0)

printf("\n\nrecord not exist");

getch();

void modify()

int no,found=0;

system("cls");
printf("\n\n\tTo Modify ");

printf("\n\n\tPlease Enter The roll number of student");

scanf("%d",&no);

fptr=fopen("F:\\test\\student.dat","rb+");

while((fread(&stud,sizeof(stud),1,fptr))>0 && found==0)

if(stud.rollno==no)

printf("\nRoll number of student : %d",stud.rollno);

printf("\nName of student : %s",stud.name);

printf("\nMarks in Physics : %d",stud.p);

printf("\nMarks in Chemistry : %d",stud.c);

printf("\nMarks in Maths : %d",stud.m);

printf("\nMarks in English : %d",stud.e);

printf("\nMarks in Computer Science : %d",stud.cs);

printf("\nPercentage of student is : %.2f",stud.per);

printf("\nGrade of student is : %c",stud.grade);

printf("\nPlease Enter The New Details of student \n");

printf(" roll number of student ");

scanf("%d",&stud.rollno);

fflush(stdin);

printf("\n Name of student ");

gets(stud.name);

printf(" marks in physics out of 100 : ");

scanf("%d",&stud.p);

printf(" marks in chemistry out of 100 : ");

scanf("%d",&stud.c);

printf(" marks in maths out of 100 : ");

scanf("%d",&stud.m);

printf(" marks in english out of 100 : ");

scanf("%d",&stud.e);
printf(" marks in computer science out of 100 : ");

scanf("%d",&stud.cs);

stud.per=(stud.p+stud.c+stud.m+stud.e+stud.cs)/5.0;

if(stud.per>=60)

stud.grade='A';

else if(stud.per>=50 && stud.per<60)

stud.grade='B';

else if(stud.per>=33 && stud.per<50)

stud.grade='C';

else

stud.grade='F';

fseek(fptr,-(long)sizeof(stud),1);

fwrite(&stud,sizeof(stud),1,fptr);

printf("\n\n\t Record Updated");

found=1;

fclose(fptr);

if(found==0)

printf("\n\n Record Not Found ");

getch();

void del()

int no;

FILE *fptr2;

system("cls");

printf("Enter The roll number of student You Want To Delete\n");

scanf("%d",&no);

fptr=fopen("F:\\test\\student.dat","rb");
fptr2=fopen("F:\\test\\Temp.dat","wb");

rewind(fptr);

while((fread(&stud,sizeof(stud),1,fptr))>0)

if(stud.rollno!=no)

fwrite(&stud,sizeof(stud),1,fptr2);

fclose(fptr2);

fclose(fptr);

remove("F:\\test\\student.dat");

rename("F:\\test\\Temp.dat","F:\\test\\student.dat");

printf("\n\n\tRecord Deleted ..");

getch();

void classr()

system("cls");

fptr=fopen("F:\\test\\student.dat","rb");

if(fptr==NULL)

printf("File not opened");

getch();

exit(0);

printf("\n\n\t\tALL STUDENTS RESULT \n\n");

printf("====================================================\n");

printf("R.No. Name P C M E CS perc Grade\n");


printf("====================================================\n");

while((fread(&stud,sizeof(stud),1,fptr))>0)

printf("%-6d %-10s %-3d %-3d %-3d %-3d %-3d %-3.2f %-


1c\n",stud.rollno,stud.name,stud.p,stud.c,stud.m,stud.e,stud.cs,stud.per,stud.grade);

fclose(fptr);

getch();

void result()

int ans,rno,a=1;

char ch;

system("cls");

printf("\nEnter\n1. Class Result\n2.Student Report Card\n3.Back to Main Menu\n");

scanf("%d",&ans);

switch(ans)

case 1 : classr();

break;

case 2 :

while(a==1){

system("cls");

printf("\n\nEnter Roll Number Of Student : ");

scanf("%d",&rno);

display1(rno);

printf("\nPress 1 to see more results\n");

scanf("%d",&a);

break;
case 3: break;

default: printf("\a");

void firstpage()

system("cls");

printf("\t\t\t\t\t\tSTUDENT REPORT CARD");

printf("\n\n\n\n\n\n\a\a\a\a\a\aProject by- ABHISHEK CHAUHAN\nB.Tech CSE IIIrd SEM\nUniv roll-


1918119\nSec-C\n");

printf("\n\nGRAPHIC ERA HILL UNIVESITY\n\tDehradun\n");

getch();

void entry()

char ch;

system("cls");

printf("Please Enter Your Choice\n");

printf("1.create New Record\n");

printf("2.Display All Records\n");

printf("3.Search any Record\n");

printf("4.Modify Any Record\n");

printf("5.Delete Any Record\n");

printf("6.Main Menu\n");

ch=getche();
switch(ch)

case '1': system("cls");

write();

break;

case '2': display();break;

case '3': {

int num;

system("cls");

printf("\n\n\tPlease Enter The roll number ");

scanf("%d",&num);

display1(num);

break;

case '4': modify();break;

case '5': del();break;

case '6': break;

default:printf("\a INAPPROPROIATE CHOICE!!!!\n");entry();

void main()

char ch;

firstpage();

while(1)

system("cls");

printf("\n\n\n\Enter choice-\n1-Result Menu\n2-Entry\\Edit Menu\n3-Stop\n");

ch=getche();

switch(ch)

{
case '1': system("cls");

result();

break;

case '2': entry();

break;

case '3':exit(0);

default :printf("INAPPROPROIATE CHOICE!!!!\n");

REFERENCE

1- C - In Depth - 2Nd Revised Edition Deepali Srivastava

2- The C Programming Language. 2nd Edition

Book by Brian Kernighan and Dennis Ritchie

3- https://www.geeksforgeeks.org/basics-file-handling-c/

You might also like