0% found this document useful (0 votes)
4 views

Cource File OOP LAB

C++ opps

Uploaded by

Juned Khan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Cource File OOP LAB

C++ opps

Uploaded by

Juned Khan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 38

Chandigarh School of Business

Jhanjeri, Mohali-140307
Department of Computer Applications

Check-list for Lab Course

Sr.
Contents Yes/No
No.
1. Institute V/M; Department V/M/PEO; PO/PSO Statements
2. Academic Calendar
3. Lab Course Syllabus
4. Lab Course Data Sheet (with Complete details)
5. Lab Course Outcomes – Assessment Plan Sheet
6. Time Table of the Concerned Faculty Member
7. Detailed Lab Course Coverage
8. Lab Manuals
9. Quiz/Viva Sample Questions
10. Continuous Evaluation ( Lab Evaluation Sheets)
11. Sample Experiment Files (Two best , Two average & Two poor students)
12. Gaps & Plans for Add-on Experiments
13. Value Aided Experiments/Design Experiment/Open Ended Experiments
Any Innovative Method Adopted; Description
14.
(I.e. Projects/ charts/ PPTs/ Videos etc.)
15. Internal Awards Compilation Record (on Attached Performa)
Lab Course Outcomes Assessment (For NBA), Corrective Actions on CO
16.
Attainments

Prepared by: Checked by: Approved by


(Mr. Naveen Bansal) (PAQIC Members) HOD, Dept. Of Comp App
Asst. Professor, Dept. Of Comp. App.
Chandigarh School of Business
Jhanjeri, Mohali-140307
Department of Computer Applications

Institute Vision and Mission


VISION
To be the most preferred management institution developing
professional and socially responsible leaders.

MISSION
● To provide quality education through state-of-art
infrastructure and well qualified faculty.
● Inculcating managerial skills and entrepreneurship in
students through strong industry interaction.
● Focus on specialized practical oriented teaching to
enhance the analytical skills for higher studies and best
employability.
● To imbibe ethical values and social responsibility among
students.
Chandigarh School of Business
Jhanjeri, Mohali-140307
Department of Computer Applications

Department Vision and Mission

VISION
Provide research-based and world-class computer education
and training, and produce ethically sound and technically
competent versatile professionals.

MISSION
● To educate the students in the field of Computer-Science
with ever-changing technologies and skills.
● To enable the students in solving real-time problems and
make use of new technologies.
● To have industry collaboration and interaction with
professional societies for continuous development.
● To help students in becoming successful entrepreneurs.
Chandigarh School of Business
Jhanjeri, Mohali-140307
Department of Computer Applications

PROGRAMME OUTCOMES (POs)


Computer Applications Graduates will be able to:

PO1:Basic knowledge: An ability to apply knowledge of basic mathematics, science and domain
knowledge to solve the computational problems.

PO2. Discipline knowledge: An ability to apply discipline –specific knowledge to solve core
and/or applied computational problems.

PO3. Experiments and practice: An ability to plan and perform experiments and practices and
to use the results to solve computational problems.

PO4. Tools Usage: Apply appropriate technologies and tools with an understanding of
limitations.

PO5. Profession and society: Demonstrate knowledge to assess societal, health, safety, legal and
cultural issues and the consequent responsibilities relevant to professional practice.

PO6. Environment and sustainability: Understand the impact of the computational solutions in
societal and environmental contexts, and demonstrate the knowledge and need for sustainable
development.

PO7. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms of the professional practice.

PO8. Individual and team work: Function effectively as an individual, and as a member or
leader in diverse/multidisciplinary teams.

PO9. Communication: An ability to communicate effectively.

PO10. Life-long learning: Recognize the need for, and have the preparation and ability to
engage in independent and life-long learning in the context of technological changes..
Chandigarh School of Business
Jhanjeri, Mohali-140307
Department of Computer Applications

Course Code: UGCA1910 (BCA2)


Course Name: Object Oriented Programming using C++ Laboratory

Program: BCA L: 0 T: 0 P: 4
Branch: Computer Applications Credits: 2
Semester: 2nd Contact hours: 4 hours per week
Internal max. marks: 60 Theory/Practical: Practical
External max. marks: 40 Duration of end semester exam (ESE): 3hrs
Total marks: 100 Elective status: Core

Prerequisite: -NA- Co requisite: -NA-


Additional material required in ESE: -NA- Course Outcomes:

CO# Course outcomes


CO1 Design the classes.
CO2 Illustrate the concept of memory representation for objects
CO3 Implement programs using OOP concepts for various problems.
CO4 Implement file handling in C++
CO5 Select the right data types to represent class properties.

Instructions: Develop all program in C++ Assignments:

1. Write a program to enter mark of 6 different subjects and find out the total mark
(Using
cin and cout statement)
2. Write a function using reference variables as arguments to swap the values of pair
of
integers.
3. Write a function to find largest of three numbers.
4. Write a program to find the factorial of a number.
5. Define a class to represent a bank account which includes the following members
as Data members:
a) Name of the depositor b) Account Number c) Withdrawal amount d) Balance
amount in the account
Member Functions:
a) To assign initial values b)To deposit an amount c) To withdraw an amount after
checking the balance d) To display name and balance.
6. Write the above program for handling n number of account holders using array of
objects.
Chandigarh School of Business
Jhanjeri, Mohali-140307
Department of Computer Applications

7. Write a C++ program to compute area of right angle triangle, equilateral triangle,
isosceles triangle using function overloading concept.
8. Consider a publishing company that markets both book and audio cassette
version to its works. Create a class Publication that stores the title (a string) and
price (type float) of a publication. Derive the following two classes from the
above Publication class: Book which adds a page count (int) and Tape which
adds a playing time in minutes(float). Each class should have get_data() function
to get its data from the user at the keyboard. Write the main() function to test the
Book and Tape classes by creating instances of them asking the user to fill in
data with get_data() and then
displaying it using put_data().
9 Consider an example of declaring the examination result. Design three classes
. student, exam and result. The student has data members such as rollno, name.
Create the lass exam by inheriting the student class. The exam class adds data
members representing the marks scored in 5 subjects. Derive the result from
exam-class and it has own data
members like total, avg.
1 Write a program for overloading of Unary ++ operator.
0
.
1 Write a program for overloading of Binary + operator.
1
.
1 Write a program of Virtual Functions.
2
.
1 Write a program of Abstract Classes.
3
.
1 Write a program to read and write from file.
4
.

TEXT/REFERENCE BOOKS:
T/R BOOK TITLE/AUTHORS/PUBLICATION
1
Object Oriented Programming with C++, E. Balagurusami, Fourth Edition, Tata Mc-
Graw Hill.
2 Object Oriented Programming in Turbo C++, Robert Lafore, Fourth Edition Galgotia
Publications.
3 The C++ Programming Language, Bjarna Stroustrup, Third Edition, Addison-
Wesley Publishing Company.
4 Object Oriented Programming Using C++, Salaria, R. S, Fourth Edition, Khanna
Chandigarh School of Business
Jhanjeri, Mohali-140307
Department of Computer Applications

Book Publishing

Subject Incharge: HOD (Computer Applications)

Mr. Naveen Bansal Dr. Anil Kumar Lamba

COURSE OUTCOMES:
SNo
DESCRIPTION PO(1..12) MAPPING
.
CO1 Design the classes. PO(1,2,3,4,5)
CO2 Illustrate the concept of memory representation for objects PO(1,2,3,4,5,8)
CO3 Implement programs using OOP concepts for various problems. PO(1,2,3,4,6)
CO4 Implement file handling in C++ PO(1,2,3,4)
CO5 Select the right data types to represent class properties. PO(1,2,3,4)
.COURSE OUTCOMES VS POS MAPPING (DETAILED; HIGH:3; MEDIUM:2; LOW:1):
SNO PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10
Design the
CO1 3 2 3 3 3 - - - - -
classes.
Illustrate the
concept of
CO2 memory 3 2 3 2 1 - - 1 - -
representation for
objects
Implement
programs using
CO3 3 2 3 3 - 2 - - - -
OOP concepts for
various problems.
Implement file
CO4 2 2 3 2 - - - - - -
handling in C++
Select the right
data types to
CO5 2 2 3 3 - - - - - -
represent class
properties.

POs & PSO REFERENCE:


PO1 Basic knowledge PO6 Environment and sustainability
PO2 Discipline knowledge PO7 Ethics
PO3 Experiments and practice PO8 Individual and team work
PO4 Tools Usage PO9 Communication
PO5 Profession and society PO10 Life-long learning
Chandigarh School of Business
Jhanjeri, Mohali-140307
Department of Computer Applications

JUSTIFICATION FOR MAPPING


PO
SNO JUSTIFICATION
MAPPED
Design the classes by applying knowledge of basic mathematics, science
CO1-PO1 H
and domain knowledge to solve the computational problems
Design the classes by applying discipline –specific knowledge to solve
CO1-PO2 M
core and/or applied computational problems
Design the classes to plan and perform experiments and practices and to
CO1-PO3 H
use the results to solve computational problems
Apply appropriate technologies and tools with an understanding of
CO1-PO4 H
limitations so as to design the classes.
Design the classes to demonstrate knowledge to assess societal, health,
CO1-PO5 H safety, legal and cultural issues and the consequent responsibilities
relevant to professional practice.
Illustrate the concept of memory representation for objects by applying
CO2-PO1 H knowledge of basic mathematics, science and domain knowledge to solve
the computational problems
Illustrate the concept of memory representation for objects by applying
CO2-PO2 M discipline –specific knowledge to solve core and/or applied computational
problems
plan and perform experiments and practices and to use the results to solve
CO2-PO3 H computational problems to illustrate the concept of memory representation
for objects
Apply appropriate technologies and tools with an understanding of
CO2-PO4 M
limitations to illustrate the concept of memory representation for objects
Illustrate the concept of memory representation for objects to demonstrate
CO2-PO5 L knowledge to assess societal, health, safety, legal and cultural issues and
the consequent responsibilities relevant to professional practice.
Implement programs using OOP concepts for various problems by
CO3-PO1 H applying knowledge of basic mathematics, science and domain knowledge
to solve the computational problems
Implement programs using OOP concepts for various problems by
CO3-PO2 M applying discipline –specific knowledge to solve core and/or applied
computational problems
Implement programs using OOP concepts for various problems to plan
CO3-PO3 H and perform experiments and practices and to use the results to solve
computational problems
Implement programs using OOP concepts for various
CO3-PO4 H problems by Applying appropriate technologies and
tools with an understanding of limitations.
Understand the impact of the computational solutions in societal and
environmental contexts, and demonstrate the knowledge and need for
CO3-PO6 M
sustainable development by implementing programs using OOP concepts
for various problems
Implement file handling in C++ by applying knowledge of basic
CO4-PO1 M mathematics, science and domain knowledge to solve the computational
problems
CO4-PO2 M Implement file handling in C++ by applying discipline –specific
Chandigarh School of Business
Jhanjeri, Mohali-140307
Department of Computer Applications

knowledge to solve core and/or applied computational problems


Implement file handling in C++ by planning and performing experiments
CO4-PO3 H
and practices and to use the results to solve computational problems
Apply appropriate technologies and tools with an understanding of
CO4-PO4 M
limitations to implement file handling in C++
Select the right data types to represent class properties by applying
CO5-PO1 M knowledge of basic mathematics, science and domain knowledge to solve
the computational problems
Select the right data types to represent class properties by applying
CO5-PO2 M discipline –specific knowledge to solve core and/or applied computational
problems
Select the right data types to represent class properties to plan and perform
CO5-PO3 H experiments and practices and to use the results to solve computational
problems
Select the right data types to represent class properties by applying
CO5-PO4 H
appropriate technologies and tools with an understanding of limitations.

GAPES IN THE SYLLABUS - TO MEET INDUSTRY/PROFESSION REQUIREMENTS, POs:


SNO DESCRIPTION PROPOSED ACTIONS / ACTION TAKEN
1 This Pointer Extra Class/Content Beyond Syllabus
2 Static Keyword Extra Class/Content Beyond Syllabus
PROPOSED ACTIONS: TOPICS BEYOND SYLLABUS/ASSIGNMENT/INDUSTRY VISIT/GUEST
LECTURER/NPTEL ETC

TOPICS BEYOND SYLLABUS/ADVANCED TOPICS/DESIGN:


SNO DESCRIPTION PROPOSED ACTIONS / ACTION TAKEN
1 Templates PPT Shared/Content Beyond Syllabus
2 Nested Classes Extra Class/Content Beyond Syllabus
3 Scope Resolution Ooperator Extra Class/Content Beyond Syllabus

WEB SOURCE REFERENCES:


1 https://www.tutorialspoint.com/cplusplus/
2 https://www.youtube.com/watch?v=ifJBkPiPYAg
3 http://www.cplusplus.com/doc/tutorial/
4 https://www.w3schools.com/cpp/default.asp
5 https://www.geeksforgeeks.org/c-plus-plus/

DELIVERY/INSTRUCTIONAL METHODOLOGIES:
✔ CHALK & TALK, PPT ✔ STUD. ✔ WEB RESOURCES ✔ NPTEL/OTHERS
ASSIGNMENT
✔ LCD/SMART ✔ STUD. SEMINARS ☐ ADD-ON COURSES ☐ WEBNIARS
BOARDS
Chandigarh School of Business
Jhanjeri, Mohali-140307
Department of Computer Applications

ASSESSMENT METHODOLOGIES-DIRECT
✔ ASSIGNMENTS ✔ STUD. SEMINARS ✔ TESTS/MODEL ✔ UNIV.
EXAMS EXAMINATION
✔ STUD. LAB ☐ STUD. VIVA ☐ MINI/MAJOR ☐ CERTIFICATIONS
PRACTICES PROJECTS
☐ ADD-ON COURSES ☐ OTHERS

ASSESSMENT METHODOLOGIES-INDIRECT
✔ ASSESSMENT OF COURSE OUTCOMES (BY ✔ STUDENT FEEDBACK ON FACULTY
FEEDBACK, ONCE) (TWICE)
☐ ASSESSMENT OF MINI/MAJOR PROJECTS BY ☐ OTHERS
EXT. EXPERTS

INNOVATIONS IN TEACHING/LEARNING/EVALUATION PROCESSES:


1. Group Discussion.
2. PPT by students.
3. Open book test.
4. Online courses
5. MCQ’s

Prepared by: Checked by: Approved by


(MS. BALJEET KAUE SIDHU) (PAQIC Members) (Dr.SAURABH SHARMA)
Asst. Professor, Dept. Of Comp. App. HOD, Dept. Of Comp App
Chandigarh School of Business
Jhanjeri, Mohali-140307
Department of Computer Applications

COURSE PLAN
VISION:
Provide research-based and world-class computer education and training, and produce ethically
sound and technically competent versatile professionals.
MISSION:

● Develop the ability to adapt to technological skills to fulfill the challenges of the ever-
evolving global world.

● Induce knowledge that foster continuous improvement, self-learning, and innovation for
higher education.

● Create a unique organizational value-based culture, professionalism in education, service,


and management and learner-centered education of excellence
PROGRAM EDUCATIONAL OBJECTIVES:

● provide a foundation of business practices and computing principles to effectively manage


and use enterprise software and information systems.

● Students get to know about business software and help them to analyze the requirements
for developing systems.

● BCA graduates from CGC Jhanjeri will have the option to specialize in system software,
legacy application software or mobile applications.

Subject: Object Oriented Contact Hour: L Total


Programming using C++ Laboratory Semester: 4 = 4
(UGCA1910) 2nd 4 per week

Branch: Computer Applications Faculty: Ms Baljeet Kaur Sidhu


Prerequisite Course: NA
Teacher Centric Approach TC1: Chalk and Talk, TC2: PPT, TC3: Video Lectures etc (Add
any other as per our NIT Poly)
Learner Centric Approach: LC1: Assignment, LC2: Mini project, LC3: Quiz, LC 4: Seminar
on recent trends LC5: Group Task etc (Add any other as per our NIT Poly
Chandigarh School of Business
Jhanjeri, Mohali-140307
Department of Computer Applications

Lecture CO Planned Actual


Topics to be covered Sign
Number Covered Date Date
Write a program to enter mark of 6 different CO1,
1 subjects and find out the total mark (Using CO3,
cin and cout statement) CO5
Write a function using reference variables as CO1,
2 arguments to swap the values of pair of CO3,
Integers. CO5
CO1,
CO2,
3 Write a function to find largest of three numbers.
CO3,
CO5
CO1,
4 Write a program to find the factorial of a number. CO3,
CO5
Define a class to represent a bank account which
includes the following members as Data
members:
a) Name of the depositor b) Account Number c) CO1,
Withdrawal amount d) Balance amount in the CO2,
5
account CO3,
Member Functions: CO5
a) To assign initial values b)To deposit an
amount c) To withdraw an amount after checking
the balance d) To display name and balance.
Write the above program for handling n number CO1,
of account holders using array of CO2,
6
CO3,
objects. CO5
Write a C++ program to compute area of right CO1,
angle triangle, equilateral triangle, CO2,
7
isosceles triangle using function overloading CO3,
concept. CO5
Consider a publishing company that markets
both book and audio cassette version to its
works. Create a class Publication that stores the
title (a string) and price (type float) of a
publication. Derive the following two classes
from the above Publication class: Book which CO1,
adds a page count (int) and Tape which adds a CO2,
8
playing time in minutes(float). Each class CO3,
should have get_data() function to get its data CO5
from the user at the keyboard. Write the main()
function to test the Book and Tape classes by
creating instances of them asking the user to fill
in data with get_data() and then
displaying it using put_data().
9 Consider an example of declaring the CO1,
Chandigarh School of Business
Jhanjeri, Mohali-140307
Department of Computer Applications

examination result. Design three classes student,


exam and result. The student has data members
such as rollno, name. Create the lass exam by
CO2,
inheriting the student class. The exam class adds
CO3,
data members representing the marks scored in
CO5
5 subjects. Derive the result from exam-class
and it has own data
members like total, avg.
Write a program for overloading of Unary ++ CO1,
operator. CO2,
10
CO3,
CO5
Write a program for overloading of Binary + CO1,
operator. CO2,
11
CO3,
CO5
CO1,
CO2,
12 Write a program of Virtual Functions.
CO3,
CO5
CO1,
CO2,
13 Write a program of Abstract Classes.
CO3,
CO5
14 Write a program to read and write from file.
CO4

Prepared by: Checked by: Approved by


(MS. BALJEET KAUE SIDHU) (PAQIC Members) (Dr.SAURABH SHARMA)
Asst. Professor, Dept. Of Comp. App. HOD, Dept. Of Comp App
Chandigarh School of Business
Jhanjeri, Mohali-140307
Department of Computer Applications

Practical -1

1 Aim: Write a program to enter mark of 6 different subjects and find out the total mark
(Using cin and cout statement)
2. Software Used: Tool : Code blocks/ Turbo C++
Operating system : Windows 10 professional
Hardware : P-IV, RAM-2 GB , SSD 120
3. Source Code:
#include<iostream.h>
#include<conio.h>
int main() {
// To store the values of five subjects
float sub_1, sub_2, sub_3, sub_4, sub_5;
float total = 0.00;
cout << "Enter the marks of five subjects::\n";
cin >> sub_1 >> sub_2 >> sub_3 >> sub_4 >> sub_5;
// It will calculate the Total, Average and Percentage
total = sub_1 + sub_2 + sub_3 + sub_4 + sub_5;
// It will produce the final output
cout << "\nThe Total marks = " << total << "/500\n";
return 0;
}

Output

Enter the marks of five subjects::


95
85
74
64
53
The Total marks = 371/500
Chandigarh School of Business
Jhanjeri, Mohali-140307
Department of Computer Applications

2 Aim: Write a function using reference variables as arguments to swap the values of pair of
integers.
2. Software Used: Tool : Code blocks/ Turbo C++
Operating system : Windows 10 professional
Hardware : P-IV, RAM-2 GB , SSD 120
3. Source Code:
#include<iostream.h>
#include<conio.h>
class abc
{
private:
int t;
public:
void swap(int *a, int *b)
{
t=*a;
*a=*b;
*b=t;
}
};
void main()
{
int a,b;
clrscr();
abc sa;
cout<<"Enter the values of A: ";
cin>>a;
cout<<"Enter the values of B: ";
cin>>b;
sa.swap(&a,&b);
cout<<"\nValue of A is: "<<a;
cout<<"\nValue of B is: "<<b;
getch();
}
OUTPUT
Enter the values of A:
20
Enter the values of B:
30
Value of A is 30
Value of B is 20
Chandigarh School of Business
Jhanjeri, Mohali-140307
Department of Computer Applications

3 Aim: Write a function to find largest of three numbers.


2. Software Used: Tool : Code blocks/ Turbo C++
Operating system : Windows 10 professional
Hardware : P-IV, RAM-2 GB , SSD 120
3. Source Code:
#include<iostream>
using namespace std;
int main() {
int num1,num2,num3;
cout<<" Enter value for first number";
cin>>num1;
cout<<" Enter value for second number";
cin>>num2;
cout<<" Enter value for third number";
cin>>num3;
if(num1>num2&&num1>num3) {
cout<<" First number is greatest:"<<endl<<"whick is= "<<num1;
} else if(num2>num1&&num2>num3) {
cout<<" Second number is greatest"<<endl<<"whick is= "<<num2;
} else {
cout<<" Third number is greatest"<<endl<<"whick is= "<<num3;
}
return 0;
}

OUTPUT
Enter value for first number
56
Enter value for second number
96
Enter value for third number
75
Second number is greatest
Chandigarh School of Business
Jhanjeri, Mohali-140307
Department of Computer Applications

4 Aim: Write a program to find the factorial of a number.


2. Software Used: Tool : Code blocks/ Turbo C++
Operating system : Windows 10 professional
Hardware : P-IV, RAM-2 GB , SSD 120
3. Source Code:
#include <iostream>
using namespace std;
int main() {
int n;
long double factorial = 1.0;
cout << "Enter a positive integer: ";
cin >> n;
if (n < 0)
cout << "Error! Factorial of a negative number doesn't exist.";
else {
for(int i = 1; i <= n; ++i) {
factorial *= i;
}
cout << "Factorial of " << n << " = " << factorial;
}
return 0;
}
OUTPUT
Enter a positive integer:
5
Factorial of = 120
Chandigarh School of Business
Jhanjeri, Mohali-140307
Department of Computer Applications

5 Aim: Define a class to represent a bank account which includes the following members as
Data members:
a) Name of the depositor b) Account Number c) Withdrawal amount d) Balance
amount in the account
Member Functions:
b) To assign initial values b)To deposit an amount c) To withdraw an amount after
checking the balance d) To display name and balance.
2. Software Used: Tool : Code blocks/ Turbo C++
Operating system : Windows 10 professional
Hardware : P-IV, RAM-2 GB , SSD 120
3. Source Code:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
class Bank
{
public:
char name[20];
int account_number;
int withdrawl_amount;
int balance;
void initialize()
{
cout<<"\nEnter Account Holders Name:";
gets(name);
cout<<"\nEnter account number:";
cin>>account_number;
cout<<"\Enter balance to deposit:";
cin>>balance;
}
void deposit()
{
int bal;
cout<<"\nEnter the amout to deposit:";
cin>>bal;
balance+=bal;
cout<<"\nAmount deposited successfuly\nYour New
Balance:"<<balance;
}
void withdrawl()
{
int withdrawl_amount;
cout<<"\nYour balance :"<<balance<<"\nEnter amount to withdraw:";
cin>> withdrawl_amount;
if(withdrawl_amount <=balance)
Chandigarh School of Business
Jhanjeri, Mohali-140307
Department of Computer Applications

{
balance-= withdrawl_amount;
cout<<"\nRemaining Balance:"<<balance;
}
else
{
exit(0);
}
}
void display()
{
cout<<"\nName :";
puts(name);
cout<<"\nBalance :"<<balance;
}
};
void main()
{
int i;
clrscr();
Bank bk;
bk.initialize();
cout<<"\n1. Your Information\n2. Deposit\n3. Withdraw\nEnter your
choice\n";
cin>>i;
if(i==1)
{
bk.display();
}
else if(i==2)
{
bk.deposit();
}
else if(i==3)
{
bk.withdrawl();
}
getch();
}
OUTPUT
Enter Account Holders Name:
Baljeet
Enter account number:
1221
Enter balance to deposit:
12000
1. Your Information
2. Deposit
Chandigarh School of Business
Jhanjeri, Mohali-140307
Department of Computer Applications

3. Withdraw
Enter your choice
2
Enter the amout to deposit:
1500
Amount deposited successfully
Your New Balance:13500
Chandigarh School of Business
Jhanjeri, Mohali-140307
Department of Computer Applications

6 Aim: Write the above program for handling n number of account holders using array of
objects.
2. Software Used: Tool : Code blocks/ Turbo C++
Operating system : Windows 10 professional
Hardware : P-IV, RAM-2 GB , SSD 120
3. Source Code:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
class Bank
{
public:
char name[20];
int account_number;
int withdrawl_amount;
int balance;
void initialize()
{
cout<<"\nEnter Account Holders Name:";
gets(name);
cout<<"\nEnter account number:";
cin>>account_number;
cout<<"\Enter balance to deposit:";
cin>>balance;
}
void deposit()
{
int bal;
cout<<"\nEnter the amout to deposit:";
cin>>bal;
balance+=bal;
cout<<"\nAmount deposited successfuly\nYour New
Balance:"<<balance;
}
void withdrawl()
{
int withdrawl_amount;
cout<<"\nYour balance :"<<balance<<"\nEnter amount to withdraw:";
cin>> withdrawl_amount;
if(withdrawl_amount <=balance)
{
balance-= withdrawl_amount;
cout<<"\nRemaining Balance:"<<balance;
}
else
{
Chandigarh School of Business
Jhanjeri, Mohali-140307
Department of Computer Applications

exit(0);
}
}
void display()
{
cout<<"\nName :";
puts(name);
cout<<"\nBalance :"<<balance;
}
};
void main()
{
int i,j,n,accNum;
clrscr();
Bank bk[10];
cout<<"\ENTER NO OF ACCOUNT HOLDERS";
cin>>n;
for(j=0; j<n;j++)
{
bk[j].initialize();
}
cout<<"\n1. Your Information\n2. Deposit\n3. Withdraw\nEnter your
choice\n";
cin>>i;
cout<<"\n Enter account number to proceed\n";
cin>>accNum;
for(j=0; j<n;j++)
{
if(bk[j].account_number==accNum)
{
if(i==1)
{
bk[j].display();
}
else if(i==2)
{
bk[j].deposit();
}
else if(i==3)
{
bk[j].withdrawl();
}
}
}
getch();
}
OUTPUT
Chandigarh School of Business
Jhanjeri, Mohali-140307
Department of Computer Applications
Chandigarh School of Business
Jhanjeri, Mohali-140307
Department of Computer Applications

7 Aim: Write a C++ program to compute area of right angle triangle, equilateral triangle,
isosceles triangle using function overloading concept.
2. Software Used: Tool : Code blocks/ Turbo C++
Operating system : Windows 10 professional
Hardware : P-IV, RAM-2 GB , SSD 120
3. Source Code:
#include<iostream.h>
#include<math.h>
#include<conio.h>
class geometry
{
public:
float area(float side)
{
return(sqrt(3)*side*side/4);//area of equilateral triangle
}
float area(int a, int b)
{
return((b/2)*sqrt((a*a)-(b*b)/4));
}
float area(float base, float height)
{
return((base*height)/2);
}
};
int main()
{
geometry g;
float s,b,h;
int x, y;
int ch;
do
{
cout<<"\n\n *****Menu***** \n";
cout<<"\n 1. Area of right angled triangle";
cout<<"\n 2. Area of issoceless Triangle";
cout<<"\n 3. Area of equilateral triangle";
cout<<"\n 4. Exit";
cout<<"\n\n Enter Your Choice : ";
cin>>ch;
switch(ch)
{

case 1:
{
cout<<"\n Enter the base: ";
cin>>b;
Chandigarh School of Business
Jhanjeri, Mohali-140307
Department of Computer Applications

cout<<"\n Enter the height: ";


cin>>h;
cout<<"\n Area of right angled triangle :
"<<g.area(b,h);
break;
}
case 2:
{
cout<<"\n Enter the sides of issoceless Triangle :
";
cout<<"\n Enter the length of equal side : ";
cin>>x;
cout<<"\n Enter the length of unequal side : ";
cin>>y;
cout<<"\n Area of issoceless Triangle :
"<<g.area(x,y);
break;
}
case 3:
{
cout<<"\n Enter the side of eqilateral triangle:
";
cin>>s;
cout<<"\n Area of equilateral triangle :
"<<g.area(s);
break;
}
case 4:
default:
cout<<"\n Invalid Choice... ";
}
}while(ch!=4);
return 0;
}
OUTPUT
Chandigarh School of Business
Jhanjeri, Mohali-140307
Department of Computer Applications
Chandigarh School of Business
Jhanjeri, Mohali-140307
Department of Computer Applications

8 Aim: Consider a publishing company that markets both book and audio cassette version
to its works. Create a class Publication that stores the title (a string) and price (type
float) of a publication. Derive the following two classes from the above Publication
class: Book which adds a page count (int) and Tape which adds a playing time in
minutes(float). Each class should have get_data() function to get its data from the user
at the keyboard. Write the main() function to test the Book and Tape classes by
creating instances of them asking the user to fill in data with get_data() and then
displaying it using put_data().
2. Software Used: Tool : Code blocks/ Turbo C++
Operating system : Windows 10 professional
Hardware : P-IV, RAM-2 GB , SSD 120
3. Source Code:
#include <iostream.h>
#include <string.h>
#include <conio.h>
using namespace std;
class publication
{
private:
char title[30];
float price;
public:
void getdata(void)
{
cout << "Enter title of publication: ";
gets(title);
cout << "Enter price of publication: ";
cin >> price;

}
void putdata(void)
{
cout << "Publication title: " << title << endl;
cout << "Publication price: " << price<<endl;
}
};
class book :public publication
{
private:
int pagecount;
public:
void getdata(void)
{
publication::getdata(); //call publication class
function to get data
Chandigarh School of Business
Jhanjeri, Mohali-140307
Department of Computer Applications

cout << "Enter Book Page Count: "; //Acquire book data
from user
cin >> pagecount;
}
void putdata(void)
{
publication::putdata(); //Show Publication data
cout << "Book page count: " << pagecount << endl; //Show
book data
}
};
class tape :public publication
{
private:
float ptime;
public:
void getdata(void)
{
publication::getdata();
cout << "Enter tap's playing time: ";
cin >> ptime;
}
void putdata(void)
{
publication::putdata();
cout << "Tap's playing time: " << ptime << endl;
}
};
void main(void)
{
book b;
tape t;
b.getdata();
t.getdata();
b.putdata();
t.putdata();
getch();
}
Output:
Chandigarh School of Business
Jhanjeri, Mohali-140307
Department of Computer Applications

9 Aim: Consider an example of declaring the examination result. Design three classes
student, exam and result. The student has data members such as rollno, name. Create
the class exam by inheriting the student class. The exam class adds data members
representing the marks scored in 5 subjects. Derive the result from exam-class and it
has own data members like total, avg.
2. Software Used: Tool : Code blocks/ Turbo C++
Operating system : Windows 10 professional
Hardware : P-IV, RAM-2 GB , SSD 120
3. Source Code:
#include<iostream.h>
#include<string.h>
class Student
{
int roll_no;
char name[25];
public:
void ReadStudentData(void);
void DisplayStudentData(void); };
class Exam :public Student
{
protected:
int marks[6];
public :
void ReadExamMarks(void);
void DisplayExamMarks(void);
};
class Result : public Exam
{
int total_marks;
public : void Display(void);
};
void Student :: ReadStudentData()
{
cout<<" \n Enetr the Name:"<<endll;
cin>>name;
cout<< " \n Enter the Roll No.:"< <endll;
cin>>roll_no;
}
void Student :: DisplayStudentData()
{
cout<<" \n Name :"<<name<<endll;
cout <<" \n Roll No. :"<<roll_no <<endll;
}
void Exam::ReadExamMarks()
{
cout<<" \nEnter Marks :"<<endl;
Chandigarh School of Business
Jhanjeri, Mohali-140307
Department of Computer Applications

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


{
Cout<<" \n Marks scored in subject"<<i+1<<"<Max:100>"<<endl;
Cin>>marks[i];
}
}
void Exam::DisplayExamMarks()
{
for (int i=0; i<6;i++)
{
cout<<" \n Marks scored in subject"<<i+1<<":"<<marks[i];
}
}
void Result::Display()
{
total_marks=0;
for (int i=0; i<6;i++)
{
total_marks=total_marks+marks[i];
cout<<" \n Total Marks scored in six subjects :"<<total_marks;
}
}
void main()
{
Result objr;
objr.ReadStudentData();
objr.ReadExamMarks();
objr.DisplayExamMarks();
objr.Display();
}
Chandigarh School of Business
Jhanjeri, Mohali-140307
Department of Computer Applications

10 Aim: Write a program for overloading of Unary ++ operator.


2. Software Used: Tool : Code blocks/ Turbo C++
Operating system : Windows 10 professional
Hardware : P-IV, RAM-2 GB , SSD 120
3. Source Code:

3. Source Code:
#include<iostream.h>
#include<conio.h>
class complex
{
int a, b, c;
public:
complex()
{
}
void getvalue() {
cout << "Enter the Two Numbers:";
cin >> a>>b;
}
void operator++() {
a = ++a;
b = ++b;
}
void operator--() {
a = --a;
b = --b;
}
void display() {
cout << a << "+\t" << b << "i" << endl;
}
};
void main() {
clrscr();
complex obj;
obj.getvalue();
obj++;
cout << "Increment Complex Number\n";
obj.display();
obj--;
cout << "Decrement Complex Number\n";
obj.display();
getch();
}
Chandigarh School of Business
Jhanjeri, Mohali-140307
Department of Computer Applications

OUTPUT
Enter the two numbers: 3 6
Increment Complex Number
4 + 7i
Decrement Complex Number
3 + 6i
Chandigarh School of Business
Jhanjeri, Mohali-140307
Department of Computer Applications

11 Aim: Write a program for overloading of Binary + operator.


2. Software Used: Tool : Code blocks/ Turbo C++
Operating system : Windows 10 professional
Hardware : P-IV, RAM-2 GB , SSD 120
3. Source Code:
#include<iostream.h>
#include<conio.h>
class complex
{
int a, b;
public:
void getvalue() {
cout << "Enter the value of Complex Numbers a,b:";
cin >> a>>b;
}
complex operator+(complex ob) {
complex t;
t.a = a + ob.a;
t.b = b + ob.b;
return (t);
}
complex operator-(complex ob) {
complex t;
t.a = a - ob.a;
t.b = b - ob.b;
return (t);
}
void display() {
cout << a << "+" << b << "i" << "\n";
}
};
void main() {
clrscr();
complex obj1, obj2, result, result1;
obj1.getvalue();
obj2.getvalue();
result = obj1 + obj2;
result1 = obj1 - obj2;
cout << "Input Values:\n";
obj1.display();
obj2.display();
cout << "Result:";
result.display();
result1.display();

getch();
}
OUTPUT:
Chandigarh School of Business
Jhanjeri, Mohali-140307
Department of Computer Applications

Enter the value of Complex Numbers a, b


4 5
Enter the value of Complex Numbers a, b
2 2
Input Values
4 + 5i
2 + 2i
Result
6 + 7i
2 + 3i
Chandigarh School of Business
Jhanjeri, Mohali-140307
Department of Computer Applications

12 Aim: Write a program of Virtual Functions.


2. Software Used: Tool : Code blocks/ Turbo C++
Operating system : Windows 10 professional
Hardware : P-IV, RAM-2 GB , SSD 120
3. Source Code:
#include<iostream>
using namespace std;
class base
{
public:
virtual void print()
{
cout << "print base class\n";
}

void show()
{
cout << "show base class\n";
}
};
class derived : public base
{
public:
void print()
{
cout << "print derived class\n";
}

void show()
{
cout << "show derived class\n";
}
};
int main()
{
base *bptr;
derived d;
bptr = &d;
// Virtual function, binded at runtime
bptr->print();
// Non-virtual function, binded at compile time
bptr->show();
return 0;
}

OUTPUT:
print derived class
Chandigarh School of Business
Jhanjeri, Mohali-140307
Department of Computer Applications

show base class


Chandigarh School of Business
Jhanjeri, Mohali-140307
Department of Computer Applications

13 Aim: Write a program of Abstract Classes


2. Software Used:
Tool : Code blocks/ Turbo C++
Operating system : Windows 10 professional
Hardware : P-IV, RAM-2 GB , SSD 120

3. Source Code:
#include<iostream>
using namespace std;

class Base
{
int x;
public:
virtual void fun() = 0;
int getX() { return x; }
};

// This class inherits from Base and implements fun()


class Derived: public Base
{
int y;
public:
void fun() { cout << "fun() called"; }
};

int main(void)
{
Derived d;
d.fun();
return 0;
}
Output:
fun() called
Chandigarh School of Business
Jhanjeri, Mohali-140307
Department of Computer Applications

14 Aim: Write a program to read and write from file.


2. Software Used:
Tool : Code blocks/ Turbo C++
Operating system : Windows 10 professional
Hardware : P-IV, RAM-2 GB , SSD 120

3. Source Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
fstream newfile;
newfile.open("tpoint.txt",ios::out); // open a file to perform write
operation using file object
if(newfile.is_open()) //checking whether the file is open {
newfile<<"Tutorials point \n"; //inserting text
newfile.close(); //close the file object
}
newfile.open("tpoint.txt",ios::in); //open a file to perform read
operation using file object
if (newfile.is_open()){ //checking whether the file is open
string tp;
while(getline(newfile, tp)){ //read data from file object and put it
into string.
cout << tp << "\n"; //print the data of the string
}
newfile.close(); //close the file object.
}
}

OUTPUT
Tutorials point

You might also like