You are on page 1of 46

Name: Viniyeta Baviskar

Roll no: 05
Mca 1st shift

SOURCE CODE (sortname.cpp):


#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
char st[10][10],temp[10];
int i, j, n;
clrscr();
cout<<"Enter the no. of names:";
cin>>n;
cout<<"Enter the different names:";
for(i=0; i< n; i++)
cin>>st[i];
for(i=0; i< n; i++)
{
for(j=i; j< n-1; j++)
{
if(strcmp(st[i], st[j+1]) >0)
{
strcpy(temp,st[i]);
strcpy(st[i],st[j+1]);
strcpy(st[j+1],temp);
}
}
}
cout<<"Given names after ascending order:";
for(i=0;i<5;i++)
cout<< st[i];
getch();
}

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift

Output:

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift

SOURCE CODE (volume.cpp):


#include<iostream.h>
#include<conio.h>
void volume(int);
void volume(float,float);
void volume(float);

void main()
{
int s,r,h,r1;
clrscr();
cout<<"Enter side of cube : ";
cin>>s;
volume(s);

cout<<"Enter radius and height of cylinder : ";


cin>>r>>h;
volume(r,h);

cout<<"Enter radius of sphere : ";


cin>>r1;
volume(r1);

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift
getch();
}

void volume(int s)
{
int ans;
ans=s*s*s;
cout<<"The volume of cube = "<<ans<<endl;
}

void volume(float r,float h)


{
int ans;
ans=3.14*r*r*h;
cout<<"The volume of cylinder = "<<ans<<endl;
}

void volume(float r1)


{
int ans;
ans=(4.0/3.0)*3.14*r1*r1*r1;
cout<<"The volume of sphere = "<<ans<<endl;
}

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift

Output :

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift

SOURCE CODE: (hra.cpp)


#include<iostream.h>
#include<conio.h>
class salary
{
int hra, da,gross,basic_salary;
public: void input()
{
cout<<"enter basic salary";
cin>>basic_salary;
}
void display()
{
cout<<"\nbasic salary="<<basic_salary;

}
friend float calculate(salary s)
};
float calculate(salary s)
{
float hra,da,gross;
hra=.6*s.basic_salary;
da=.98*s.basic_salary;
gross=s.basic_salary+s.hra+s.da;
cout<<"\nhra="<<hra;
cout<<"\nda="<<da;

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift
cout<<"\ngross="<<gross;
}

void main()
{
clrscr();
salary s;
s.input();
s.display();
calculate(s);
getch();
}

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift

OUTPUT

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift

SOURCE CODE (Armstrong.cpp):

#include<iostream.h>
#include<conio.h>
int main()
{
int a,d,sum=0,c;
clrscr();
cout<<"enter number:";
cin>>a;
c=a;
while(a>0)
{
d=a%10;
sum=sum+d*d*d;
a=a/10;
}
if (c==sum)
{
cout<<"armstrong";
}
else
{
cout<<"not armstrong";
}
getch();
}

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift

OUTPUT:

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift

SOURCE CODE : (housing.cpp)


#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
struct s
{
char name[20];
char add[50],remark[100];
int amt_of_main;
long int mob;
}s1[1];
for(int i=0;i<10;i++)
{
cout<<"Enter your name";
gets(s1[i].name);
cout<<"Enter your address";
gets(s1[i].add);
cout<<"Enter your mobile no.";
cin>>s1[i].mob;
cout<<"Enter you amount of maintance";
cin>>s1[i].amt_of_main;
cout<<"Enter your remarks";
gets(s1[i].remark);
cout<<endl;
}
cout<<endl<<endl;
cout<<"Details entered are as follows:===>>"<<endl<<endl;
for(i=0;i<10;i++)
{
cout<<"Name:"<<s1[i].name<<endl;
cout<<"Address"<<s1[i].add<<endl;

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift
cout<<"Mobile no."<<s1[i].mob<<endl;
cout<<"Maintaince amount"<<s1[i].amt_of_main<<endl;
cout<<"Remarks"<<s1[i].remark;
cout<<endl<<endl;
}
getch();
}

OUTPUT:

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift

SOURCE CODE (inline.cpp):


#include<iostream.h>
#include<conio.h>
const pi = 3.14159;
inline float area(float x)
{
return(pi*x*x);
}
inline float per(float x)
{
return(2*pi*x);
}
void main()
{
float r;
clrscr();
cout<<"enter radius:-";
cin>>r;
cout<<"\narea of a circle is:-"<<area(r);
cout<<"\nperimeter of a circle is :-"<<per(r);
getch();

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift
}

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift

OUTPUT:

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift

SOURCE CODE(PALLINDROME):

#include<iostream.h>
#include<conio.h>
#include<string.h>
int main()
{
char n[10],n1[10];
int a;

int no,d,c,rev=0;
clrscr();
cout<<"enter string"<<n1;
cin>>n1;
strcpy(n,n1);
strrev(n1);
a=strcmp(n1,n);
if(a==0)
{
cout<<"string is pallindrome"<<endl;
}

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift
else
{
cout<<"string is not pallindrome"<<endl;
}
cout<<"enter number"<<endl;
cin>>no;
int num=no;
while(no>0)
{
d=no%10;
rev=(rev*10)+d;
no=no/10;
}
cout<<"reverse="<<rev;
if(num==rev)
{
cout<<"pallindrome"<<endl;
}
else
{
cout<<"not pallindrome"<<endl;
}
getch();

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift
}

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift

OUTPUT:

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift

SOURCE CODE: (ascending.cpp)


#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int list[5];
cout<<"Enter five numbers :- "<<endl;
for(int i=0;i<=4;i++)
{
cin>>list[i];
}
cout<<"Entered numbers are :- "<<endl;
for(i=0;i<5;i++)
{
cout<<list[i]<<endl;
}
int temp=0;
for(i=0;i<4;i++)
{
for(int j=i+1;j<5;j++)
{
if(list[i]>list[j])
{
temp=list[i];
list[i]=list[j];
list[j]=temp;
}
}
}
cout<<endl;
cout<<"Minimum number is :- "<<list[0]<<endl;
cout<<"Maximum number is :- "<<list[4]<<endl;

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift
cout<<"Numbers in Ascending order :-"<<endl;
for(i=0;i<5;i++)
{
cout<<list[i]<<endl;
}
getch();
}

OUTPUT:

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift

SOURCE CODE (string.cpp):


#include<iostream.h>

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift
#include<conio.h>
#include<string.h>
void main()
{
//char str[20],str1[30];
char *str,*str1;
int ch,a,l;
clrscr();
cout<<"\nWhich string operation do you want to perform?";
cout<<"\n1 : String concatenation";
cout<<"\n2 : String comparison";
cout<<"\n3 : Substring of a string";
cout<<"\n4 : String size(length)"<<endl;
cin>>ch;
switch(ch)
{
case 1:
cout<<"Enter the first string : ";
cin>>str;
cout<<"Enter the second string : ";
cin>>str1;
strcat(str,str1);
cout<<str<<endl;
break;
case 2:
cout<<"Enter the first string : ";
cin>>str;
cout<<"Enter the second string : ";
cin>>str1;
a=strcmp(str,str1);
if(a==0)
cout<<"Both strings are same";
else
cout<<"Both strings are not same";
break;
case 3:
int i,s,end;
cout<<"Enter the string : " ;

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift
cin>>str;
cout<<"Enter start point : ";
cin>>s;
cout<<"Enter end point : ";
cin>>end;
cout<<"Substring is ";
for(i=s-1;i<=end;i++)
{
cout<<str[i];
}
break;
case 4:
cout<<"Enter the string : ";
cin>>str;
l=strlen(str);
cout<<"Size of the string : "<<l;
break;
default:
cout<<"Invalid choice";
break;

}
getch();
}

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift

OUTPUT:

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift

SOURCE CODE: (bank.cpp)

#include<iostream.h>

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift
#include<conio.h>
class Bank
{
float accno,bal;
char name[25];
public:
void getdata()
{
cout<<"Enter the Depositor name : ";
cin>>name;
cout<<"Enter the account no : ";
cin>>accno;
cout<<"Enter the Balance : ";
cin>>bal;
}
void deposit()
{
float d;
cout<<"Enter the deposit amount : ";
cin>>d;
bal=bal+d;
cout<<"New balance is "<<bal;
}
void withdraw()
{
float wd;
cout<<"Enter the withdraw amount : ";
cin>>wd;
if (wd>500)
{
wd=bal-wd;
cout<<"The balance after withdraw is "<<wd;
}
else
{
cout<<"You do not have sufficient balance";
}
}
void display()
{
cout<<"Depositor Name --> "<<name;
cout<<"\nAccount Number --> "<<accno;

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift
cout<<"\nBalance --> "<<bal<<endl;

}
};
void main()
{
int ch;
clrscr();
Bank b1;
b1.getdata();
clrscr();
b1.display();

cout<<"\nPress 1 for Deposit \nPress 2 for Withdraw\n";


cin>>ch;
switch(ch)
{
case 1:
b1.deposit();
break;
case 2:
b1.withdraw();
break;
default:
cout<<"Invalid Input";
break;
}
getch();
}

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift

OUTPUT:

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift

OUTPUT:

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift

SOURCE CODE: (distance.cpp)


#include<iostream.h>

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift
#include<conio.h>
class Feet;
class Meter
{
private:
int met,cm;

public:
Meter()
{
}
Meter(int a, int b)
{
met=a;
cm=b;
}
void display()
{
cout<<"Distance is "<<met<<"meters and "<<cm<<"cms.";
}

friend void add_Meter(Meter,Feet);


friend void add_Feet(Meter,Feet);

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift
};
class Feet
{
private:
int ft,in;

public:
Feet()
{
}
Feet(int a,int b)
{
ft=a;
in=b;
}
void display()
{
cout<<"\nDistance is "<<ft<<"Feet & "<<in<<"inches.";
}
friend void add_Meter(Meter,Feet);
friend void add_Feet(Meter,Feet);
};
void add_Meter(Meter d1,Feet d2)

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift
{
int temp;
temp=(d2.ft*12+d2.in)*2.54+(d1.met*100+d1.cm);
int a=temp/100;
int b=temp%100;
Meter d5(a,b);
d5.display();
}
void add_Feet(Meter d3,Feet d4)
{
int temp;
temp=(d3.met*100+d3.cm)*.393701+(d4.ft*12+d4.in);
int a=temp/12;
int b=temp%12;
Feet d5(a,b);
d5.display();
}
void main()
{
clrscr();
Meter m1(18,13);
Feet f1(12,19);
add_Meter(m1,f1);

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift
add_Feet(m1,f1);
getch();
}

OUTPUT:

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift

SOURCE CODE: (swapping.cpp)


#include<iostream.h>
#include<conio.h>
void swap_value(int x,int y)
{
int temp;
temp=x;
x=y;
y=temp;
cout<<"Swapped values are : "<<x<<" "<<y;
}
void swap_ref(int &x,int &y)
{
int temp;
temp=x;
x=y;
y=temp;
cout<<"Swapped values are : "<<x<<" "<<y;

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift
}
void swap_var(int x,int y)
{
x=x+y;
y=x-y;
x=x-y;
cout<<"Swapped values are : "<<x<<" "<<y;
}

void main()
{
int a,b,ch;
clrscr();
cout<<"Enter the first number : ";
cin>>a;
cout<<"Enter the second number : ";
cin>>b;
cout<<"\n\nHow would you like to swap the values ?"<<endl;
cout<<"1 : call by value";
cout<<"\n2 : call by reference";
cout<<"\n3 : by using two variables"<<endl;
cin>>ch;

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift
switch(ch)
{
case 1:
swap_value(a,b);
break;
case 2:
swap_ref(a,b);
break;
case 3:
swap_var(a,b);
break;
default:
cout<<"Invalid choice.";
break;
}

getch();
}

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift

OUTPUT:

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift

Reverse.cpp:

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift
#include<iostream.h>
#include<conio.h>
void reverse1();
void reverse2();
void main()
{
clrscr();
int choice;
cout<<"Enter 1 : to reverse the string "<<endl;
cout<<"Enter 2 : to reverse the number "<<endl;
cin>>choice;
switch (choice)
{
case 1:
reverse1();
break;
case 2:
reverse2();
break;
default:
cout<<"Please enter correct choice "<<endl;
}

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift

getch();
}
void reverse1()
{
char name[50];
cout<<"Enter name : ";
cin>>name;
int i,l=0;
for(i=0;name[i]!=NULL;i++)
{
l++;
}
for(i=l-1;i>=0;i--)
{
cout<<name[i];
}
cout<<"\t\t";
}
void reverse2()
{
long int no;
int rev;

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift
cout<<"Enter the number : ";

cin>>no;
while(no>0)
{
rev=no%10;
cout<<rev;
no=no/10;
}
cout<<"\n\n";
}

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift

OUTPUT:

Name: Viniyeta Baviskar


Roll no: 05
Mca 1st shift

You might also like