You are on page 1of 13

switch case reactangle

#include<stdio.h>
#include<conio.h>
#include<math.h>
#define pi 3.14
void main()
{
int choice;
//char* area_of;
float a,b;
float area=0.0;
clrscr();
printf("Enter the choice \n\t1 for Square\n\t2 for Circle\n\t3 for Rectangle\n\t
4 for Triangle");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("\n-----SQARE-----");
printf("\nEnter the Side of Square");
scanf("%f",&a);
area=a*a;
//
area_of="Square";
break;
case 2:
printf("\n-----Circle-----");
printf("\nEnter the Radius of Circle");
scanf("%f",&a);
//
area=200;
//
area=pi*pow(a,2);
area=a*a*pi;
//
area_of="Circle";
break;
case 3:
printf("\n-----Rectangle-----");
printf("\nEnter the Length : ");
scanf("%f",&a);
printf("\nEnter the Breadth : ");
scanf("%f",&b);
area=a*b;
//
area_of="Rectangle";
break;
case 4:
printf("\n-----Triangle-----");
printf("\nEnter the base");
scanf("%f",&a);
printf("\nEnter the height");
scanf("%f",&b);
area=0.5*a*b;
//
area_of="Triangle";
break;
default:
printf("\n-----heheheheheheehehehehehe \nWRONG CHOICE");
break;
}
//printf("\nArea of %c is %f",area_of,area);

printf("%f",area);
getch();
}
2.greatest of two no
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d;
clrscr();
printf("\nEnter the First no");
scanf("%d",&a);
printf("\nEnter the Second no");
scanf("%d",&b);
printf("\nEnter the Third no");
scanf("%d",&c);
if(a>b&&a>c)
d=a;
else if(b>a&&b>c)
d=b;
else
d=c;
printf("The greatest of three no.'s is %d",d);
getch();
}
3.bill
#include<stdio.h>
#include<conio.h>
void main()
{
float n;
clrscr();
printf("Enter the no of hours you have used the internet");
scanf("%f",&n);
//printf("%f",n);
if(n==1)
printf("the bill amount is 20Rs");
else if(n<1)
printf("the bill amount is 15Rs");
else printf("the bill amount is 50Rs");
getch();
}
4.print no in tab form
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,j;
clrscr();
printf("Enter the number\n");
scanf("%d",&n);

for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
printf("\t%d",i);
printf("\n");
}
getch();
}
5.prime no
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,j;
clrscr();
printf("Enter the number\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
printf("\t%d",i);
printf("\n");
}
getch();
}
6.celcius tu feh
#include<stdio.h>
#include<conio.h>
void main()
{
float cel,feh;
clrscr();
printf("\nEnter temp in feh : ");
scanf("%f",&feh);
cel=(feh-32)*5/9;
printf("\n%.4f feh=%.2f cel",feh,cel);
getch();
}
7.youngest person
#include <stdio.h>
#include<conio.h>
int main()
{
int array[100], n, c, d, swap;
clrscr();
printf("Enter number of members\n");
scanf("%d", &n);
printf("Enter %d ages\n", n);
for (c = 0; c < n; c++)

scanf("%d", &array[c]);
for (c = 0 ; c <
{
for (d = 0 ; d
{
if (array[d]
{
swap
array[d]
array[d+1]
}
}
}

( n - 1 ); c++)
< n - c - 1; d++)
> array[d+1]) /* For decreasing order use < */
= array[d];
= array[d+1];
= swap;

printf("\nYougest member's age is %d",array[0]);


printf("\nEldest member's age is %d",array[n-1]);
getch();
return 0;
}
8.room
#include<iostream.h>
#include<conio.h>
struct dist
{
int feet;
float inches;
};
struct room
{
dist length;
dist width;
};
void main()
{
room dining;
clrscr();
dining.length.feet=13;
dining.length.inches=65;
dining.width.feet=10;
dining.width.inches=10;
float l=dining.length.feet*dining.length.inches;
float w=dining.length.feet*dining.width.inches;
cout<<"area is "<<l+w;
getch();
}
9.reactangle
#include<iostream.h>
#include<conio.h>
class Rectangle
{
int length,breadth;
public:
void setValues(int,int);
int area()

{
return length*breadth;
}
};
void Rectangle::setValues(int a,int b)
{
length=a;
breadth=b;
}
void main()
{
int a,b;
Rectangle r;
clrscr();
cout<<"Enter the length and breadth for Rectangle";
cin>>a>>b;
r.setValues(a,b);
cout<<"Area of rectangle is "<<r.area();
getch();
}
10.nest
#include<iostream.h>
#include<conio.h>
class Set
{
int m,n;
public:
void input();
void display();
int largest();
};
void Set::input()
{
cout<<"Enter the values for m & n";
cin>>m>>n;
display();
}
int Set::largest()
{
if(m>n)
return m;
else return n;
}
void Set::display()
{
cout<<"Largest no is "<<largest();
}
void main()
{
Set s;
clrscr();
s.input();
getch();
}
11.inheritance

#include<iostream.h>
#include<conio.h>
class part1
{
protected:
int a,b;
float x;
public: void display();
};
class part2:part1
{
public:
void setvalues(int,int);
};
void part2::setvalues(int p,int q)
{
a=p;
b=q;
display();
}
void part1::display()
{
cout<<"The value for a is "<<a<<"\nThe value for b is "<<b;
}
void main()
{
part2 p2;
clrscr();
p2.setvalues(10,20);
getch();
}
12.employee
#include<iostream.h>
#include<conio.h>
struct Employee
{
protected:
int empno;
int compensasation;
public:
void getData()
{
cout<<"\nEnter The Emp No : ";
cin>>empno;
cout<<"\nEnter the Compensastion : ";
cin>>compensasation;
}
void display()
{
cout<<"\nEmp NO : "<<empno;
cout<<"\nEmployee Compensastion : "<<compensasation;
}
};

void main()
{
int i=0;
Employee e[3];
clrscr();
for(i=0;i<3;i++)
{
e[i].getData();
}
for(i=0;i<3;i++)
{
e[i].display();
}
getch();
}
13.date validation
#include<iostream.h>
#include<conio.h>
struct Date
{
protected:
int month,date,year;
int errorCount;
//string errorM,errorD,errorY;
public:
void getData()
{
cout<<"\nEnter The Date in DD-MM-YYYY format";
cin>>date;
cout<<"-";
cin>>month;
cout<<"-";
cin>>year;
}
void validMonth(int);
void validDate(int, int, int);
void validYear(int);
void display(int d,int m,int y)
{
if(errorCount==0)
cout<<d<<"-"<<m<<"-"<<y;
else
cout<<"\nPlease Solve the Errors";
}
void validate()
{
errorCount=0;
validMonth(month);
validDate(month,date,year);
validYear(year);
display(date,month,year);
}
};
void Date::validYear(int y)
{
if(y<1950||y>2050)
{
cout<<"\nPlease Enter Valid Year";

errorCount++;
}
}
void Date::validMonth(int m)
{
if(m>12||m<1)
{
cout<<"\nEntered Month is in wrong format";
errorCount++;
}
}
void Date::validDate(int m,int d,int y)
{
if(m==1||m==3||m==5||m==6||m==8||m==10||m==12)
{
if(d<0||d>31)
{
cout<<"\nEntered Date is in wrong format";
errorCount++;
}
}
else if(m==4||m==7||m==9||m==11)
{
if(d<0||d>30)
{
cout<<"\nEntered Date is in wrong format";
errorCount++;
}
}
else if(m==2)
{
if(y%4==0)
{
if(d<0||d>28)
{
cout<<"\nEntered Date must be within 0-28 since it is a Leap Year";
errorCount++;
}
}
else
{
if(d<0&&d>29)
{
cout<<"\nEntered Date must be within 0-29";
errorCount++;
}
}
}
}
void main()
{
Date d;
clrscr();
d.getData();
d.validate();
getch();
}
14.bank

#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class bank
{
private:
int accno;
char type[30];
float amount;
public:
void getData()
{
cout<<"Enter the Account No"<<endl;
cin>>accno;
cout<<"Enter the type of the account"<<endl;
gets(type);
cout<<"Enter the amount"<<endl;
cin>>amount;
}
void showData()
{
cout<<"Account no:"<<accno<<endl;
cout<<"Type of Account:"<<type<<endl;
cout<<"Amount : "<<amount<<endl;
}
bank()
{
getData();
showData();
}
};
void main()
{
int n;
clrscr();
bank b;
getch();
}
15.constructor
#include<iostream.h>
#include<conio.h>
class constructor
{
private:
int a,b;
public:
constructor()
{
a=10;
b=20;
cout<<"This is Default Constructor"<<endl;
cout<<a<<"+"<<b<<"="<<a+b<<endl;
}
constructor(int a,int b)
{
this->a=a;
this->b=b;

cout<<"This is Parameterised Constructor"<<endl;


cout<<a<<"+"<<b<<"="<<a+b<<endl;
}
};
void main()
{
clrscr();
constructor();
constructor c;
constructor c1(10,20);
constructor(30,40);
getch();
}
16.matrix
#include<iostream.h>
#include<conio.h>
class Matrix
{
private:
int a[3][3],b[3][3],i,j;
public:
Matrix()
{
getData();
showData();
}
void getData()
{
cout<<"Enter the values for Martrix A"<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
cin>>a[i][j];
}
cout<<"Enter the values for Matrix B"<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
cin>>b[i][j];
}
}
void showData()
{
cout<<"Entered Matrices are:"<<endl;
cout<<"maxtrix A : "<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<a[i][j]<<" ";
if(j==2)
cout<<endl;
}
}
cout<<"maxtrix B : "<<endl;
for(i=0;i<3;i++)
{

for(j=0;j<3;j++)
{
cout<<b[i][j]<<" ";
if(j==2)
cout<<endl;
}
}
cout<<"After Multiplication"<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<a[i][j]*b[j][i]<<" ";
if(j==2)
cout<<endl;
}
}
}
};
void main()
{
clrscr();
Matrix m;
getch();
}
17.recursive fn
#include<iostream.h>
#include<conio.h>
class Fact
{
private:
int n;
public:
Fact()
{
cout<<"Enter a positive integer: ";
cin>>n;
Fact(n);
}
int multiplyNumbers(int n)
{
if (n >= 1)
return n*multiplyNumbers(n-1);
else
return 1;
}
Fact(int i)
{
cout<<"Factorial of "<<i<<" = "<<multiplyNumbers(i);
}
};
void main()
{

clrscr();
Fact f;
getch();
}
18.transpose of matrix
#include<iostream.h>
#include<conio.h>
class Matrix
{
private:
int a[3][3],i,j;
public:
Matrix()
{
getData();
showData();
}
void getData()
{
cout<<"Enter the values for Martrix A"<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
cin>>a[i][j];
}
}
void showData()
{
cout<<"maxtrix A : "<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<a[i][j]<<" ";
if(j==2)
cout<<endl;
}
}
cout<<"Transpose of Matrix A is :"<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<a[j][i]<<" ";
if(j==2)
cout<<endl;
}
}
}
};
void main()
{
clrscr();
Matrix m;

getch();
}