To Display Your Profile / Detail

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 14

1.

To display your profile / detail:


#include<iostream.h>
#include<conio.h>
class profile
{
public:
void output()
{
cout<<"\n\t\t Name :Agilan ";
cout<<"\n\t\t Gender :Male";
cout<<"\n\t\t Age :18";
cout<<"\n\t\t Mail-Id :aki_lan@ymail.com";
cout<<"\n\t\t Mobile no. :9786335384";
}
};
void main()
{
profile s;
clrscr();
s.output();
getch();
}

2. To print “hello world” infinite times:


#include<iostream.h>
void main()
{
for(;;)
cout<<"\tHello World";
}
4. To display your First Semester Mark List:
#include<iostream.h>
#include<conio.h>
class marklist
{
public:
void line()
{
cout<<"\n";
for(int i=0;i<40;i++)
cout<<"**";
}
void display()
{
cout<<"\n\t\tStudent Name :Agilan";
cout<<"\n\t\tRegister number :103478008";
cout<<"\n\t\t***********************************";
cout<<"\n\t\tMathamatics I :8B";
cout<<"\n\t\tPhysics :8B";
cout<<"\n\t\tChemistry :8B";
cout<<"\n\t\tBEEE :8B";
cout<<"\n\t\tThermodynamics :8B";
cout<<"\n\t\tComputer Program :8B";
cout<<"\n\t\tCP Lab :7C";
cout<<"\n\t\tBEEE Lab :9A";
cout<<"\n\t\tEG Lab :7C";
}

};
void main()
{
marklist s;
clrscr();
s.line();
s.display();
s.line();
getch();
}
5. To get an String input and display it in column vise:
#include<iostream.h>
#include<conio.h>
void main()
{
char str[100];
clrscr();
cout<<"\nEnter any String....";
cin>>str;
for(int i=0;i<100;i++)
{
cout<<"\n\t"<<str[i];
if(str[i]=='\0')
break;
}
getch();
}

6. To find greatest of three number:


#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
cout<<"\nEnter 3 Numbers.........";
cin>>a>>b>>c;
if((a>b)&&(a>c))
cout<<"\n\n*** A is Biggest***";
else if(b>c)
cout<<"\n\n*** B is Biggest***";
else
cout<<"\n\n*** C is Biggest***";
getch();
}
7. To generate electricity bill :
#include<iostream.h>
#include<conio.h>
class ebill
{
public:
char n[30];
float pr,cr,unit,rs,r;
void getdata();
void process();
void display();
void line();
};
void ebill :: getdata()
{
cout<<"\nEnter coustmor Name : ";
cin>>n;
cout<<"\nEnter previous reading : ";
cin>>pr;
cout<<"\nEnter Current reading : ";
cin>>cr;
}
void ebill :: process()
{
unit=cr-pr;
if(unit<=50)
rs=unit;
else if((unit>50)&&(unit<=100))
rs=50+((unit-50)*2);
else
rs=150+((unit-100)*3);
r=rs;
}
void ebill :: display()
{
cout<<"\n\t\n\t\tNAME : "<<n;
cout<<"\n\t\n\t\tCurrent Reading : "<<cr;
cout<<"\n\t\n\t\tPrevious Reading : "<<pr;
cout<<"\n\t\n\t\t ----------";
cout<<"\n\t\n\t\tTotal Unit comsumed : "<<unit;
cout<<"\n\t\n\t ----------";
cout<<"\n\t\n\t\tBill Amount RS: "<<r;
cout<<"\n\n";

}
void main()
{
ebill s;
clrscr();
s.getdata();
s.process();
clrscr();
s.display();
getch();

8. To find the biggest and smallest number in an array :


#include<iostream.h>
#include<conio.h>
void main()
{
int a[100],i,n,max=0,min=10000;
clrscr();
cout<<"Enter the number of terms.....";
cin>>n;
for(i=0;i<n;i++)
cin>>a[i];
for(i=0;i<n;i++)
{
if(a[i]>max)
max=a[i];
else if(a[i]<min)
min=a[i];
}
cout<<"\n\n\t\tThe Biggest Number....."<<max;
cout<<"\n\n\t\tThe Smallest Number...."<<min;
getch();
}
9. To sum the series 1+3+5+……..nth :
#include<iostream.h>
#include<conio.h>
void main()
{
int n,sum=0,temp=1;
clrscr();
cout<<"\n\tEnter the nth Term.....";
cin>>n;
for(int i=1;i<=n;i++)
{
sum=sum+temp;
temp=temp+2;

}
cout<<"\n\tThe Sum Series.........."<<sum;
getch();
}

10. To find the factorial :


#include<iostream.h>
#include<conio.h>
void main()
{
int n,i,f=1;
clrscr();
cout<<"\n\tEnter number of terms....";
cin>>n;
for(i=1;i<=n;i++)
f=f*i;
cout<<"\n\tThe Factorial is........."<<f;
getch();
}
11. To generate and sum the series

#include<iostream.h>
#include<conio.h>
void main()
{
int n,i,f,sum=0,j;
clrscr();
cout<<"\n\tEnter number of terms....";
cin>>n;
for(j=1;j<=n;j++)
{
f=1;
for(i=1;i<=j;i++)
f=f*i;
sum=sum+(f/j);
}
cout<<"\n\tThe Factorial is........."<<sum;
getch();
}

12. To exchange two number without using third variable:


#include<iostream.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
cout<<"\n\tEnter Two Numbers......";
cin>>a>>b;
b=a+b;
a=b-a;
b=b-a;
cout<<"\n\tThe Value of A :"<<a;
cout<<"\n\tThe Value of B :"<<b;
getch();
}
13. To get n vale in a array and print it in reverse oreder
#include<iostream.h>
#include<conio.h>
void main()
{
int a[100],i,n;
clrscr();
cout<<"Enter the number of terms.....";
cin>>n;
for(i=0;i<n;i++)
cin>>a[i];
for(i=n-1;i>=0;i--)
cout<<"\n\t\t"<<a[i];
getch();
}

14. To get a string and reverse it


#include <iostream.h>
#include <stdio.h>
#include <conio.h>
void main()
{
char str[10],temp;
int i,len,j;
clrscr();
cout<<"Enter String : ";
for(i=0;(str[i]=getchar())!='\n';i++);
len=i-1;
j=i;
for(i=0;i<j/2;i++)
{
temp=str[i];
str[i]=str[len];
str[len--]=temp;
}

cout<<"The reverse : "<<str;


getch();
}
15. To count nmber of word in a string
#include<stdio.h>
#include<iostream.h>
#include<conio.h>
void main()
{
int i,len,wd=0;
char s[1000];
clrscr();
for(i=1;(s[i]=getchar())!=EOF;i++);
len=i;
for(i=1;i<=len;i++)
{
if(s[i]==' '||s[i]=='\n'||s[i]==EOF)
wd++;
}
cout<<"\nNumber of Word = "<<wd;
getch();
}

16. To convert decimal to binary :

#include<iostream.h>
#include<conio.h>
void main()
{
int d,b[50],i,j;
clrscr();
cout<<"\n\tEnter the Decimal no...";
cin>>d;
for(i=1;i>0;i++)
{
b[i]=d%2;
d=d/2;
if(d==0)
break;
}
cout<<"\n\tBinary Number..........";
for(j=i;j>0;j--)
cout<<b[j];
getch();
}

17. To convert decimal to hexadecimal

#include<iostream.h>
#include<conio.h>
void main()
{
char h[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
long int d,b[50],i,j;
clrscr();
cout<<"\n\tEnter the Decimal no...";
cin>>d;
for(i=1;i>0;i++)
{
b[i]=d%16;
d=d/16;
if(d==0)
break;
}
cout<<"\n\tHexadecimal Number.....";
for(j=i;j>0;j--)
cout<<h[b[j]];
getch();
}
18. To add two strings
#include<iostream.h>
#include<conio.h>
#include<process.h>
void main()
{
char str1[50],str2[50],str[100];
clrscr();
cout<<"\n\tEnter Two words......";
cin>>str1>>str2;
int i,j;
for(i=0;i<100;i++)
{
str[i]=str1[i];
if(str1[i]=='\0')
{
for(j=0;j<50;j++)
{
str[i+j]=str2[j];
if(str2[j]=='\0')
{
cout<<"==>"<<str;
getch();
exit(0);
}
}

}
}
}

19. To print the system date


#include <dos.h>
#include <iostream.h>
#include <conio.h>
void main()
{
struct date d;
int dd,mm,yy;
clrscr();
getdate(&d);
yy=d.da_year;
dd=d.da_day;
mm=d.da_mon;
cout<<"\nSystem Current Date :";
cout<<dd<<"/"<<mm<<"/"<<yy;
getch();
}
20. To generate a random number
#include <stdlib.h>
#include <iostream.h>
#include <conio.h>
void main()
{
int i;
clrscr();
cout<<"20 random numbers from 0 to 99\n\n";
for(i=0; i<20; i++)
cout<<rand()%100<<"\t";
getch();
}
C++ ASSIGNMENT

Submitted by

AGILAN.A
ICE -II YEAR
SMVEC
17.08.2010

You might also like