Professional Documents
Culture Documents
For
“OBJECT ORIENTED PROGRAMMING USING C++”
[BCA303P]
PART-A
1) Write a C ++ Program to prepare a shopping list.
Program:
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
const size =2;
class shopping
{
private:
char name[25];
intqty;
float rate;
public:
int amount;
void getdata()
{
cout<<endl<<"\nEnter the item name:";
cin>>name;
cout<<endl<<"Enter the rate:";
cin>>rate;
cout<<endl<<"Enter the quantity:\n";
cin>>qty;
}
void printdata()
{
cout<<name;
cout<<"\t\t"<<rate;
cout<<"\t\t"<<qty;
amount=rate * qty;
cout<<"\t\t"<<amount<<endl;
}
};
void main()
{
shopping item[size];
int total=0;
clrscr();
cout<<"\n Enter your shopping details\n";
for(inti=0;i<=size;i++)
item[i].getdata();
cout<<"\n Hello your shopping list is as follows\n";
for(i=0;i<=size;i++)
{
item[i].printdata();
total=total+item[i].amount;
}
cout<<"\n Total\t\t"<<total;
getch();
}
Input:
Output:
}
void bank::disp_det()
{
cout<<"\n Account Details\n";
cout<<"\n Name of the Depositor:"<<name<<endl;
cout<<"\n Account Number:"<<accno<<endl;
cout<<"\n Account Type:"<<acctype<<endl;
cout<<"\n Balance Amount:"<<balance<<endl;
}
void main()
{
clrscr();
bank obj;
int choice;
while(choice!=0)
{
cout<<"\n 1.New Account\n 2.Deposit\n 3.Withdraw\n 4. Display Account Status\n 0
to exit\n";
cout<<"\n Enter your choice:";
cin>>choice;
switch(choice)
{
case 0: cout<<"Exiting.. Program\n";
exit(0);
break;
case 1:obj.init();
break;
case 2:obj.deposit();
break;
case 3:obj.withdraw();
break;
case 4:obj.disp_det();
break;
default:cout<<"Choose Correct Option";
}
}
getch();
}
Input:
Step 3: In order to deposit amount, choose choice 2 and enter the amount to be
deposited.
Step 4: Choose choice 4 in order to view account details
(Amount will be added with existing amount)
Step 5: Choose choice 3 to withdraw amount and add amount to be withdrew
Step 6: Choose choice 4 to view the account status after withdrawing.
(Entered amount will be deducted from existing amount)
Step 7: Choose choice 0 to exit from the output console screen to program.
Output:
Step 1:
Step 2:
Step 3:
Step 4:
Step 5:
Step 6:
Input:
Output:
Output:
else
{
c.m=m;
c.n=x.n;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
c.a[i][j]=0;
for(k=0;k<m;k++)
c.a[i][j]=a[i][k]*x.a[k][j];
}
}
return c;
}
int main()
{
matrix A,B,C;
clrscr();
cout<<"\n Enter the matrix order and elements "<<endl;
A.inputmatrix();
cout<<"\n Enter the matrix order and elements "<<endl;
B.inputmatrix();
C=A*B;
cout<<"Product of Matrix A and B is:"<<endl;
C.outputmatrix();
getch();
return 0;
}
Input:
Step 1: Enter order and elements of Matrix A and B respectively.
Output:
cout<<"4) Exit"<<endl;
while(ch!=4)
{
cout<<"Enter your choice : ";
cin>>ch;
switch(ch)
{
case 1: Insert();
break;
case 2: Delete();
break;
case 3: Display();
break;
case 4: cout<<"Exit"<<endl;
break;
default: cout<<"Invalid choice"<<endl;
}
}
return 0;
}
Input:
Step 1: Enter Choice 1 and insert the element
Step 2: Display all the inserted elements by entering choice 3
Step 3: Enter choice 2 to delete element
Step 4: Display the existing list after deletion by entering choice 3 again
Step 5: Enter choice 4 to exit the output console screen.
Output:
cin>>s2;
cout<<"\n Subject 3:";
cin>>s3;
percen=((s1+s2+s3)/300)*100;
}
void showmarks()
{
cout<<"\n Subject1="<<s1;
cout<<"\n Subject2="<<s2;
cout<<"\n Subject3="<<s3;
cout<<"\n Percentage="<<percen;
}
};
class result:public marks
{
private:
char grade;
public:
void display()
{
showdata();
showmarks();
cout<<"\n Grade="<<getgrade();
}
char getgrade()
{
if(s1<35||s2<35||s3<35)
grade='F';
else if(percen>=75)
grade='A';
else if(percen>=60)
grade='B';
else if(percen>=50)
grade='C';
else if(percen>=35)
grade='D';
return grade;
}
};
void main()
{
clrscr();
result stud;
stud.getdata();
stud.getmarks();
stud.display();
getch();
}
Input:
Step 1: Enter details of the student and marks of respective subjects.
Step 2: If any one subject marks is less than 35 result will be Fail
Output:
switch(ch)
{
case 1:cout<<"\n Enter base and height of triangle:";
cin>>b>>h;
area(b,h);
break;
case 2:cout<<"\n Enter the side of square:";
cin>>l;
area(l);
break;
case 3:cout<<"\n Enter the length,breadth and width of rectangle:";
cin>>l>>b>>w;
break;
case 4: exit(0);
default : cout<<"Choose right option";
}
getch();
}
}
Input:
Step 1: Enter respective measurement for the selected shape.
Step 2: Area and volume of the selected shape will be displayed.
Output:
{
int x[5]={10,30,40,20,50};
float y[5]={1.1,3.3,4.4,2.2,5.5};
char a[5]={'e','i','o','a','u'};
clrscr();
bubble(x,5);
bubble(y,5);
bubble(a,5);
cout<<"\n Sorted Integer Array:\t";
for(int i=0;i<5;i++)
cout<<x[i]<<"\t";
cout<<endl;
cout<<"\n Sorted Float Array:\t";
for(int j=0;j<5;j++)
cout<<y[j]<<"\t";
cout<<endl;
cout<<"\n Sorted Charecter Array:\t";
for(int k=0;k<5;k++)
cout<<a[k]<<"\t";
cout<<endl;
getch(); Output:
}
PART-B
Input:
Step 1: Enter number of stars to be displayed in right angled triangle form.
Output:
complex c1;
cout<<"\n For equal values";
cout<<"\n Enter the equal value for real and imaginary part of number 1:\n\t";
cin>>a;
complex c2(a);
cout<<"\n For different values";
cout<<"\n Enter the real and imaginary part of number 2:\n \t ";
cin>>b>>c;
complex c3(b,c);
complex c4=sum(c2,c3);
c4.print();
getch();
}
Input:
Step 1: Enter a value for number 1
Step 2: Enter two values for number 2
Output:
Output:
Output:
else
{
c.m=m;
c.n=x.n;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
c.a[i][j]=a[i][j]+x.a[i][j];
}
}
return c;
}
int main()
{
matrix A,B,C;
clrscr();
cout<<"\n Enter the matrix order and elements "<<endl;
A.inputmatrix();
cout<<"\n Enter the matrix order and elements "<<endl;
B.inputmatrix();
C=A+B;
cout<<"Sum of Matrix A and B is:"<<endl;
C.outputmatrix();
getch();
return 0;
}
Input:
Step 1: Enter order and elements of Matrix A and B respectively.
Output:
Input:
Step 1: Compile using Alt + F9 and run using Ctrl+F9.
Step 2: Go to file menu (press Alt+F)
Step 3: Select DOS Shell
Step 4: C:\TC\Source> program_filename.exe 10 5
Step 5: Press enter to view result
Output:
Output: