prowessapps.in Miscellaneous Programs in C++

#include< iostream>
#include< math.h>
using namespace std;
class Test {
 public :
 void area(int l, int b){
  int a = l*b;
  cout<<"Area of Rectangle = "<< a;
  cout<< endl;
 }
 void area(double r) {
  double a = 3.14*r*r;
  cout<<"Area of Circle = "<< a;
  cout<< endl;
 }
 void area(int a, int b, int c ){
  double s = (a+b+c)/2.0;
  double ar;
  ar=sqrt(s*(s-a)*(s-b)*(s-c));
  cout<<"Area of Triangle = "<< ar;
  cout<< endl;
 }
 void area(int a){
  int ar = a*a;
  cout<<"Area of Square = "<< ar;
  cout<< endl;
 }
};
int main() {
 int l,b,s,s1,s2,s3;
 double r;
 cout<<"Enter Length, Breadth ";
 cin>>l>>b;
 cout<<"Enter Radius of circle ";
 cin>>r;
 cout<<"Enter Side of square ";
 cin>>s;
 cout<<"Enter Sides of triangle ";
 cin>>s1>>s2>>s3;
 Test t;
 t.area(l,b); 
 t.area(r);
 t.area(s);
 t.area(s1,s2,s3);
 return 0;
 }
OUTPUT
Enter Length, Breadth 4 3
Enter Radius of circle 7
Enter Side of square 5
Enter Sides of triangle 3 4 5
Area of Rectangle = 12
Area of Circle = 153.86
Area of Square = 25
Area of Triangle = 6

#include< iostream>
using namespace std;
class Circle {
 public:
 void area(int &r) {
  double ar = 3.14*r*r;
  cout<<"Area = "<< ar<< endl;
 }
 void circum(int &r) {
  double cir  = 2*3.14*r;
  cout<<"Circumference = "<< cir;
  cout<< endl;
 }
};
int main() {
 int a;
 cout<<"Enter Radius ";
 cin>>a;
 Circle c;
 c.area(a);
 c.circum(a);
 return 0;
}
OUTPUT
Enter Radius 7
Area = 153.86
Circumference = 43.96

#include< iostream>
using namespace std;
class Interest {
 public:
 void sim(int p,int t, int r = 20) {
  double si = p*r*t/100;
  cout<<"Simple Interest = "<< si;
  cout<< endl;
 }
};
int main() {
 Interest i ;
 i.sim(1000,3,10);
 i.sim(1000,3);
 return 0;
}
OUTPUT
Simple Interest = 300
Simple Interest = 600

#include< iostream>
using namespace std;
class Area {
 double ar;
 public :
 inline void areaCircle(int a) {
  ar = 3.14*a*a;
  cout<<"Area of Circle = "<< ar;
  cout<< endl;
 }
 inline void areaRec(int a, int b) {
  ar = a*b;
  cout<<"Area of Rectangle "<< ar;
  cout<< endl;
 }
 inline void areaTri(int a, int b) {
  ar = a*b/2;
  cout<<"Area of Triangle "<< ar;
  cout<< endl;
 }
 inline void areaSquare(int a) {
  ar = a*a;
  cout<<"Area of Square "<< ar;
  cout<< endl;
 }
};
int main() {
 Area a;
 int r,l,b,s,s1,s2;
 cout<<"Enter Radius : ";
 cin>>r;
 cout<<"Enter Length , breadth : ";
 cin>>l>>b;
 cout<<"Enter Base and Height : ";
 cin>>s1>>s2;
 cout<<"Enter Side of Square : ";
 cin>>s;
 a.areaCircle(r);
 a.areaRec(l,b);
 a.areaTri(s1,s2);
 a.areaSquare(s);
 return 0;
}
OUTPUT
Enter Radius : 7
Enter Length , breadth : 4 3
Enter Base and Height : 4 6
Enter Side of Square : 5
Area of Circle = 153.86
Area of Rectangle = 12
Area of Triangle = 12
Area of Square = 25

#include< iostream>
using namespace std;
class Student {
 string name;
 int regno;
 int mark;
 static int avg;
 public :
 void input(){
  cout<<"Enter the name ";
  getline(cin,name);
  cout<<"Enter the reg no ";
  cin>>regno;
  cout<<"Enter the marks ";
  cin>>mark;
  cin.ignore(1,'\n');
 }
 void display(){
  cout<< name<<"\t"<< regno;
  cout<<"\t"<< mark<< endl;
 }
 void findAvg(Student a[]) {
  int sum = 0;
  for(int i = 0; i<3; i++) {
   sum = sum+a[i].mark;
  }
  avg = sum/3;
 }
 static void showAvg() {
 cout<<"Avg = "<< avg<< endl;;
 }
};
int Student::avg = 0;
int main() {
 Student s[3];
 for(int i =0; i<3; i++) {
  s[i].input();
 }
 for(int i =0; i<3; i++) {
  s[i].display();
 }
 s[0].findAvg(s);
 Student::showAvg();
 return 0;
}
OUTPUT
Enter the name Alok 
Enter the reg no 12
Enter the marks 85
Enter the name Deepu
Enter the reg no 13
Enter the marks 90
Enter the name Ayan
Enter the reg no 11
Enter the marks 95
Alok	12	85
Deepu	13	90
Ayan	11	95
Avg = 90

#include< iostream>
using namespace std;
class A {
 int a;
 friend class B;
};
class B {
 int b;
 public:
 void swap2() { 
  A obj;
  cout<<"Enter Value for a ";
  cin>>obj.a;
  cout<<"Enter Value for b ";
  cin>>b;
  int temp = obj.a;
  obj.a = b;
  b = temp;
  cout<<"After Swapping \n";
  cout<<"Value in A "<< obj.a<< endl;
  cout<<"Value of B "<< b<< endl;
 }
};
int main() {
 B b;
 b.swap2();
 return 0;
}
OUTPUT
Enter Value for a 10
Enter Value for b 30
After Swapping
Value in A 30
Value in B 10

#include< iostream>
using namespace std;
class Test {
int a, b, c;
friend void add();
};
void add() {
Test t;
cout<<"Enter Two Numbers ";
cin>>t.a>>t.b;
t.c = t.a+t.b;
cout<<"Sum = "<< t.c<< endl;
}
int main() {
add();
return 0;
}
OUTPUT
Enter Two Numbers 10 20
Sum = 30


Get it on Google Play


CONTACT DETAILS

info@prowessapps.in
(8AM to 10PM):

+91-9026070669 , +91-9451396824

© 2016, prowessapps.in, All rights reserved