0% found this document useful (0 votes)
30 views17 pages

Writing Program

Uploaded by

amol raut
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)
30 views17 pages

Writing Program

Uploaded by

amol raut
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/ 17

B.C.C.A.

Part I (Sem II) Component I Session 2020-2021

Assignment No. 1

Q. Develop a C++ program to demonstrate the use of single inheritance.

Coding:-
#include<iostream.h>
#include<conio.h>
class student
{
public:
int rno;
char name[20];
void getdata()
{
cout<<"Enter Roll No.:- ";
cin>>rno;
cout<<"Enter Name:- ";
cin>>name;
}
};
class marks: student
{
public:
int m1,m2,m3,tot;
float per;
void getmarks()
{
getdata();
cout<<"Enter marks1:- ";
cin>>m1;
cout<<"Enter marks2:- ";
cin>>m2;
cout<<"Enter marks3:- ";
cin>>m3;
tot=m1+m2+m3;
per=float(tot/3);
}
void display()
{
cout<<"Roll No= "<<rno<<endl;
cout<<"Name= "<<name<<endl;
cout<<"Mark1= "<<m1<<endl;

Prof. Shailesh Janbandhu G.S. College of Commerce, Wardha


B.C.C.A. Part I (Sem II) Component I Session 2020-2021

cout<<"Mark2= "<<m2<<endl;
cout<<"Mark3= "<<m3<<endl;
cout<<"Total= "<<tot<<endl;
cout<<"Per= "<<per<<endl;
}
};
main()
{
marks stud;
clrscr();
stud.getmarks();
stud.display();
getch();
}

Output:-

Prof. Shailesh Janbandhu G.S. College of Commerce, Wardha


B.C.C.A. Part I (Sem II) Component I Session 2020-2021

Assignment No. 2

Q. Write an algorithm, draw a flowchart and develop a c++ program to find


largest number using friend function.

Coding:-
#include<iostream.h>
#include<conio.h>
class Num
{
public:
int x,y;
void num()
{
cout<<"Enter the first number:- ";
cin>>x;
cout<<"Enter the second number:- ";
cin>>y;
}
friend void max(Num m);
};
void max(Num m)
{
if (m.x>m.y)
{
cout<<"Greater Number= "<<m.x;
}
else
{
cout<<"Greater Number= "<<m.y;
}
}
void main() Output:-
{
Num a;
clrscr();
a.num();
max(a);
getch();
}

Prof. Shailesh Janbandhu G.S. College of Commerce, Wardha


B.C.C.A. Part I (Sem II) Component I Session 2020-2021

Assignment No. 3

Q. Write an algorithm, draw a flowchart and develop a C++ program in which


a function is passed, address of two variable and then alter its content

Coding:-
#include<iostream.h>
#include<conio.h>
main()
{
int x,y;
void swap(int *,int *);
clrscr();
cout<<"Enter value for x:- ";
cin>>x;
cout<<"Enter value for y:- ";
cin>>y;
clrscr();
cout<<"In main "<<endl;
cout<<"x= "<<x<<endl<<"Address of x= "<<(unsigned)&x<<endl;
cout<<"y= "<<y<<endl<<"Address of y= "<<(unsigned)&y;
swap (&x,&y);
getch();
}
void swap (int *a,int *b)
{
int *c;
*c=*a;
*a=*b;
*b=*c;
cout<<endl<<"In swap function "<<endl;
cout<<"x= "<<*a<<endl;
cout<<"Address of x= "<<(unsigned)a<<endl;
cout<<"y= "<<*b<<endl;
cout<<"Address of y= "<<(unsigned)b<<endl;
}

Output:-

Prof. Shailesh Janbandhu G.S. College of Commerce, Wardha


B.C.C.A. Part I (Sem II) Component I Session 2020-2021

Assignment No. 4

Aim : Write an algorithm, draw a flowchart and develop a C++ program to


display Fibonacci series using iteration

Coding:-
#include<iostream.h>
#include<conio.h>
void Iter_Fibo(int a)
{
int x=0,y=1,i,z;
for(i=1;i<=a-2;i++)
{
z=x+y;
cout<<z<<endl;
x=y;
y=z;
}
}
main()
{
int n;
clrscr();
cout<<"Enter Range For Series:- ";
cin>>n;
cout<<"Series With Iteration";
cout<<endl<<"0"<<endl;
cout<<"1"<<endl;
Iter_Fibo(n);
getch();
return 0;
}

Output:-

Prof. Shailesh Janbandhu G.S. College of Commerce, Wardha


B.C.C.A. Part I (Sem II) Component I Session 2020-2021

Assignment No. 5

Aim : Write an algorithm, draw a flowchart and develop a C++ program to


calculate Factorial of a number using recursion

Coding:-

#include<iostream.h>
#include<conio.h>
int Fact_Rec(int b)
{
if (b>1)
return b*Fact_Rec(b-1);
else
return 1;
}
void main()
{
int n,I,R;
clrscr();
cout<<"Enter any number:- ";
cin>>n;
cout<<"By Recursion "<<endl;
R=Fact_Rec(n);
cout<<"Factorial of "<<n<<" using Recursion is "<<R<<endl;
getch();
}

Output:-

Prof. Shailesh Janbandhu G.S. College of Commerce, Wardha


B.C.C.A. Part I (Sem II) Component I Session 2020-2021

Assignment No. 6

Aim: Write an algorithm, draw a flowchart and develop a C++ program to


perform and demonstrate ‘this Pointer’.

Coding:-
#include<iostream.h>
#include<conio.h>
class student
{
int age,rollno;
char name[20];
float per;
public:
void getdata()
{
cout<<"Enter data "<<endl;
cout<<"Roll No :- ";
cin>>rollno;
cout<<"Name:- ";
cin>>name;
cout<<"Age:- ";
cin>>age;
cout<<"Percentage= ";
cin>>per;
}
student &max(student&s1,student&s2)
{
if(per>s1.per && per>s2.per)
return *this;
else if(s1.per>per && s1.per>s2.per)
return s1;
else if(s2.per>per && s2.per>s1.per)
return s2;
}
void display()
{
clrscr();
cout<<"Roll No. :- "<<rollno<<endl;
cout<<"Name:- "<<name<<endl;
cout<<"Age:- "<<age<<endl;
cout<<"Percentage:- "<<per<<endl;
}

Prof. Shailesh Janbandhu G.S. College of Commerce, Wardha


B.C.C.A. Part I (Sem II) Component I Session 2020-2021

}
main()
{
clrscr();
student s,s1,s2,s3;
s1.getdata();
s2.getdata();
s3.getdata();
s=s3.max(s1,s2);
cout<<"Student With Highest Percentage"<<endl;
s.display();
getch();
}

Output:-

Prof. Shailesh Janbandhu G.S. College of Commerce, Wardha


B.C.C.A. Part I (Sem II) Component I Session 2020-2021

Assignment No. 7

Q. Write an algorithm draw a flowchart and develop a C++ program to perform


unary operator overloading.

Coding:-
#include<iostream.h>
#include<conio.h>
class complex
{
int a,b,c,x,y;
public:
complex(){}
void getvalue()
{
cout<<"enter the two no:- ";
cin>>a>>b;
x=a;
y=b;
}
void operator++()
{
a=++a;
b=++b;
}
void operator--()
{
a=--x;
b=--y;
}
void display()
{
cout<<a<<endl;
cout<<b<<endl;
}
};
void main()
{
complex obj;
clrscr();
obj.getvalue();
obj++;
cout<<"Increment complex number"<<endl;

Prof. Shailesh Janbandhu G.S. College of Commerce, Wardha


B.C.C.A. Part I (Sem II) Component I Session 2020-2021

obj.display();
obj--;
cout<<"Decrement complex number"<<endl;
obj.display();
getch();
}

Output:-

Prof. Shailesh Janbandhu G.S. College of Commerce, Wardha


B.C.C.A. Part I (Sem II) Component I Session 2020-2021

Assignment No. 8

Aim: Write an algorithm, draw a flowchart and develop a C++ program to


Create a class Triangle. Include overloaded functions for calculating area.
Overload assignment operator and equality operator

Coding:-
#include <iostream.h>
#include <math.h>

class Triangle
{
private:
float a,b,c,h;
public:
Triangle(){}
Triangle(float a,float b,float c)
{
this->a=a;
this->b=b;
this->c=c;
}
Triangle(float b,float h)
{
this->b=b;
this->h=h;
}
float area()
{
cout<<a; return area(this->a,this->b,this->c);
}
float area(float a,float b,float c)
{
float p=(a+b+c)/2;
return sqrt(p*(p-a)*(p-b)*(p-c));
}
// overloaded functions for calculating are
float area(float b,float h)
{ return (b+h)/2;
}
//Overload assignment operator
Triangle& Triangle::operator= (const Triangle &triangle)
{ // do the copy

Prof. Shailesh Janbandhu G.S. College of Commerce, Wardha


B.C.C.A. Part I (Sem II) Component I Session 2020-2021

this->a = triangle.a;
this->b = triangle.b;
this->c = triangle.c;
return *this;
}
//equality operator.
Triangle& Triangle::operator== (const Triangle &t1, const Triangle &t2)
{
return (t1.a == t2.a && t1.b == t2.b && t1.c == t2.c);
}
);
int main()
{
Triangle triangleABC(18,30,24);
cout<<"Area of the tringle ABC with sides 18,30,24:" <<triangleABC.area
(18,30,24)<<"\n";
Triangle triangleBH;
cout<<"Area of the tringle with base 24 and height 18:
"<<triangleBH.area(24,18)<<"\n";;

Triangle triangleCopy=triangleABC;
cout<<"Area of the copy tringle with base 24 and height 18:
"<<triangleCopy.area()<<"\n";;
if(triangleABC==triangleCopy)
{ cout<<"The triangles are equal.\n";
}
else
{
cout<<"The triangles are not equal.\n";
}

return 0;
}

Prof. Shailesh Janbandhu G.S. College of Commerce, Wardha


B.C.C.A. Part I (Sem II) Component I Session 2020-2021

Assignment No. 9

Aim : Write an algorithm, draw a flowchart and develop a C++ program to


calculate net salary of an employee using single inheritance concept. Employee
class will have fields id, name and designation Salary class will have fields
BS,HRA,DA and PF.

Coding:-

#include<iostream.h>
#include<conio.h>

class emp
{
public:
int eno;
char name[20],des[20];
void get()
{
cout<<"Enter the employee ID:";
cin>>eno;
cout<<"Enter the employee name:";
cin>>name;
cout<<"Enter the designation:";
cin>>des;
}
};

class salary:public emp


{
float bp,hra,da,pf,np;
public:
void get1()
{
cout<<"Enter the basic pay:";
cin>>bp;
hra=bp*25/100;
da=bp*10/100;
pf=bp*5/100;
}
void calculate()
{
np=bp+hra+da-pf;

Prof. Shailesh Janbandhu G.S. College of Commerce, Wardha


B.C.C.A. Part I (Sem II) Component I Session 2020-2021

}
void display()
{
cout<<eno<<"\t"<<name<<"\t"<<des<<"\t"<<bp<<"\t"<<hra<<"\t"<<da<<"\t"<
<pf<<"\t"<<np<<"\n";
}
};

void main()
{
int i,n;
char ch;
salary s[10];
clrscr();
cout<<"Enter the number of employee:";
cin>>n;
for(i=0;i<n;i++)
{
s[i].get();
s[i].get1();
s[i].calculate();
}
cout<<"\ne_no \t e_name\t des \t bp \t hra \t da \t pf \t np \n";
for(i=0;i<n;i++)
{
s[i].display();
}
getch();
}

Output:-

Prof. Shailesh Janbandhu G.S. College of Commerce, Wardha


B.C.C.A. Part I (Sem II) Component I Session 2020-2021

Assignment No. 10

Aim : Write an algorithm, draw a flowchart and develop a C++ program to


input and display the record of 3 employees. The record consists of eno, ename,
ecity and salary fields.

Coding:-
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<dos.h>
class student
{
int roll;
char name[25];
char city[20];
public:student()
{
cout<<"Welcome in student information system"<<endl;
}
void getdata()
{
cout<<"Enter rollno.:- ";
cin>>roll;
cout<<"Enter name:- ";
cin>>name;
cout<<"Enter city:- ";
cin>>city;
}
void putdata()
{
cout<<"student rollno.:- "<<roll<<endl;
cout<<"student name:- "<<name<<endl;
cout<<"student city:- "<<city<<endl;
}
};
class marks:public student
{
int sub1;
int sub2;
int sub3;
float per;

Prof. Shailesh Janbandhu G.S. College of Commerce, Wardha


B.C.C.A. Part I (Sem II) Component I Session 2020-2021

public:
void input()
{
getdata();
cout<<"enter marks for sub1:- ";
cin>>sub1;
cout<<"enter marks for sub2:- ";
cin>>sub2;
cout<<"enter marks for sub3:- ";
cin>>sub3;
}
void output()
{
putdata();
cout<<"Marks sub1= "<<sub1<<endl;
cout<<"Marks sub2= "<<sub2<<endl;
cout<<"Marks sub3= "<<sub3<<endl;
}
void calculate()
{
per=(float)(sub1+sub2+sub3)/3;
cout<<"Total percentage= "<<per<<endl;
}
};
main()
{
marks m1;
int ch;
clrscr();
do
{
cout<<"1. Input data"<<endl;
cout<<"2. Output data"<<endl;
cout<<"3.Calculate percentage"<<endl;
cout<<"4. Exit"<<endl;
cout<<"Enter your choice:- ";
cin>>ch;
clrscr();
switch(ch)
{
case 1:
m1.input();
break;

Prof. Shailesh Janbandhu G.S. College of Commerce, Wardha


B.C.C.A. Part I (Sem II) Component I Session 2020-2021

case 2:
m1.output();
break;
case 3:
m1.calculate();
break;
}
}
while(ch!=4);
getch();
}
Output:-

Prof. Shailesh Janbandhu G.S. College of Commerce, Wardha

You might also like