Structure

WAP to find annual income of employee.

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

const int size=5;

float Sal[size],sal;

int count=0;

for(int i=0;i<size;i++)

{

cout<<“Enter the monthly salary of employee:”<<i+1<<“\n”;

cin>>Sal[i];

}

for(i=0;i<size;i++)

{

sal=Sal[i]*12;

if(sal>100000)

count++;

}

cout<<count<<” Employee out of “<<size<<” employee are earning more than Rs. 1 Lakh per annum.”;

getch();

}

WAP to find the concanated string.

#include<iostream.h>

#include<conio.h>

#include<string.h>

 

void main()

{

clrscr();

char str1[25],str2[25],str3[50];

int i,j,x,k;

cout<<“Enter the first string:”;

cin.getline(str1,25);

cout<<“Enter the second string:”;

cin.getline(str2,25);

for(i=0;str1[i]!=’\0′;++i)

str3[i]=str1[i];

for(k=0;str2[k]!=’\0′;++k)

str3[i+k]=str2[k];

str3[i+k]=’\0′;

x=strlen(str3);

cout<<“The concatenated string is:”;

cout.write(str3,x);

getch();

}

WAP to delete a string.

 

#include<iostream.h>

#include<conio.h>

#include<stdio.h>

void main()

{

clrscr();

char str[100];

int i,p,n,len;

cout<<“Enter the string:”;

gets(str);

for(len=0;str[len]!=’\0′;++len);

cout<<“Enter the starting position of substring to be deleted:”;

cin>>p;

if(p>len)

cout<<“Starting position must be less than the length of the  String.Abortng!!!”;

{

cout<<“Enter the number of charaters of substring to be deleted :”;

cin>>n;

if(n+p>=len)

n=len-p+1;

for(i=p-1;str[i]!=’\0′;++i)

str[i]=str[i+n];

cout<<“String after del. string is:”<<str;

}

getch();

}

 

 

 

 

 

 

 

 

 

WAP to find that a string is pallindrome or not.

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

char str[100],c;

cout<<“Enter the string:”;

cin.getline(str,100);

for(int len=0;str[len]!=’\0′;len++);

int i,j,f=1;

for(i=0,j=len-1;i<len/2;i++,j–)

{

if(str[i]!=str[j])

{

f=0;

break;

}}

if(f!=0)

cout<<“It’s a pallindrome.”;

else

cout<<“It’s not a pallindrome.”;

getch();

}

WAP  to accept the marks of student and print the marks.

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

const int size=5;

float marks[size];

for(int i=1;i<=size;i++)

{

cout<<“Enter the marks of student [“<<i<<“]:”;

cin>>marks[i];

}

for(i=1;i<=size;i++)

cout<<“Marks of student [“<<i<<“]=”<<marks[i]<<“\n”;

getch();

}

 

 

WAP to print a string in reverse order.

#include<iostream.h>

#include<conio.h>

#include<stdio.h>

void main()

{

clrscr();

char str[100];

int i,j,k;

cout<<“Enter any string:”;

gets(str);

for(i=0;str[i]!=’\0′;++i);

char rev[100];

for(j=i-1,k=0;j>=0;–j,++k)

rev[k]=str[j];

rev[k]=’\0′;

cout<<“The string in reverse order:”;

puts(rev);

getch();

}

WAP to print the total sales and average sales.

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

const int size=5;

float sales[size],avg=0,total=0;

for(int i=0;i<size;i++)

{

cout<<“Enter the sales of day:”<<i+1<<“\n”;

cin>>sales[i];

total+=sales[i];

}

avg=total/size;

cout<<“\nTotal sales=”<<total<<“\n”;

cout<<“Average sales=”<<avg<<“\n”;

getch();

}

 

WAP to find the total number of vowels.

#include<iostream.h>

#include<conio.h>

#include<stdio.h>

void main()

{

clrscr();

char line[100];

int i,v=0;

cout<<“Enter the line:”;

gets(line);

for(i=0;line[i]!=’\0′;i++)

{

switch(line[i])

{

case ‘a’:

case ‘e’:

case ‘i’:

case ‘o’:

case ‘u’:

case ‘A’:

case ‘E’:

case ‘I’:

case ‘O’:

case ‘U’:

v++;

}

}

cout<<“The total number of vowels are:”<<v;

getch();

}

 

 

 

 

 

WAP to print the employee information.

#include<iostream.h>

#include<conio.h>

#include<stdio.h>

struct emp

{

int empno;

char name[20];

float pay;

};

emp inf;

void main()

{

clrscr();

cout<<“Enter the employee ID:”;

cin>>inf.empno;

cout<<“Enter the employee name:”;

gets(inf.name);

cout<<“Enter the basic pay of employee:”;

cin>>inf.pay;

{

cout<<“\n”<<“Employee information-“<<“\n”;

cout<<“\n”;

cout<<“The employee ID is:”<<inf.empno<<“\n”;

cout<<“The employee name is:”;

cout.write(inf.name,20)<<“\n”;

cout<<“The employee basic pay is:”<<inf.pay<<“\n”;

getch();

}

}

 

 

 

 

 

 

WAP to print the name of entered no.

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

long int a, o, t, h, th, t_th;

o=t=h=th=t_th=-1;

cout<<“Enter any number from 0 to 99999 :”;

cin>>a;

if(a/10000!=0 && a/100000==0)

{

o=a%10;

t=((a-o)%100)/10;

h=((a-t)%1000)/100;

th=((a-h)%10000)/1000;

t_th=a/10000;

}

else if(a/1000!=0 && a/10000==0)

{

o=a%10;

t=((a-o)%100)/10;

h=((a-t)%1000)/100;

th=a/1000;

}

else if(a/100!=0 && a/1000==0)

{

o=a%10;

t=((a-o)%100)/10;

h=a/100;

}

else if(a/10!=0 && a/100==0)

{

o=a%10;

t=a/10;

}

else if(a/10==0)

o=a;

else

{

cout<<“Invalid digits”;

goto end;

}

if(a==0)

{

cout<<“Zero”;

}

switch(t_th)

{

case 1 :switch(th)

{

case 1 :cout<<“Eleven thousand “;

break;

case 2 :cout<<“Twelve thousand “;

break;

case 3 :cout<<“Thirteen thousand “;

break;

case 4 :cout<<“Fourteen thousand “;

break;

case 5 :cout<<“Fifteen thousand “;

break;

case 6 :cout<<“Sixteen thousand “;

break;

case 7 :cout<<“Seventeen thousand “;

break;

case 8 :cout<<“Eight thousand “;

break;

case 9 :cout<<“Nine thousand “;

break;

default:cout<<“Ten thousand “;

break;

}

goto hundred;

case 2 :cout<<“Twenty “;

break;

case 3 :cout<<“Thirty “;

break;

case 4 :cout<<“Forty “;

break;

case 5 :cout<<“Fifty “;

break;

case 6 :cout<<“Sixty “;

break;

case 7 :cout<<“Seventy “;

break;

case 8 :cout<<“Eight “;

break;

case 9 :cout<<“Ninety “;

break;

}

switch(th)

{

case 1 :cout<<“One thousand “;

break;

case 2 :cout<<“Two thousand “;

break;

case 3 :cout<<“Three thousand “;

break;

case 4 :cout<<“Four thousand “;

break;

case 5 :cout<<“Five thousand “;

break;

case 6 :cout<<“Six thousand “;

break;

case 7 :cout<<“Seven thousand “;

break;

case 8 :cout<<“Eight thousand “;

break;

case 9 :cout<<“Nine thousand “;

break;

case 0 :cout<<“Thousand “;

break;

}

hundred:

switch(h)

{

case 1 :cout<<“One hundred “;

break;

case 2 :cout<<“Two hundred “;

break;

case 3 :cout<<“Three hundred “;

break;

case 4 :cout<<“Four hundred “;

break;

case 5 :cout<<“Five hundred “;

break;

case 6 :cout<<“Six hundred “;

break;

case 7 :cout<<“Seven hundred “;

break;

case 8 :cout<<“Eight hundred “;

break;

case 9 :cout<<“Nine hundred “;

break;

 

}

switch(t)

{

case 1 :switch(o)

{

case 1 :cout<<“Eleven”;

break;

case 2 :cout<<“Twelve”;

break;

case 3 :cout<<“Thirteen”;

break;

case 4 :cout<<“Fourteen”;

break;

case 5 :cout<<“Fifteen”;

break;

case 6 :cout<<“Sixteen”;

break;

case 7 :cout<<“Seventeen”;

break;

case 8 :cout<<“Eighteen”;

break;

case 9 :cout<<“Nineteen”;

break;

default:cout<<“Ten”;

break;

}

goto end;

case 2 :cout<<“Twenty “;

break;

case 3 :cout<<“Thirty “;

break;

case 4 :cout<<“Forty “;

break;

case 5 :cout<<“Fifty “;

break;

case 6 :cout<<“Sixty “;

break;

case 7 :cout<<“Seventy “;

break;

case 8 :cout<<“Eight “;

break;

case 9 :cout<<“Ninety “;

break;

default:cout<<“”;

break;

}

switch(o)

{

case 1 :cout<<“One”;

break;

case 2 :cout<<“Two”;

break;

case 3 :cout<<“Three”;

break;

case 4 :cout<<“Four”;

break;

case 5 :cout<<“Five”;

break;

case 6 :cout<<“Six”;

break;

case 7 :cout<<“Seven”;

break;

case 8 :cout<<“Eight”;

break;

case 9 :cout<<“Nine”;

break;

default:cout<<“”;

break;

}

end:

getch();

}

 

WAP to find roots of quadratic equation.

#include<iostream.h>

#include<conio.h>

#include<math.h>

void main()

{

clrscr();

float a,b,c;

cout<<“Enter the coefficients of x^2, x and constant:”;

cin>>a>>b>>c;

cout<<“Roots are:”<<((-1)*b+(sqrt(b*b-4*a*c)))/(2*a)<<“\n”<<((-1)*b-(sqrt(b*b-4*a*c)))/(2*a);

getch();

}

WAP to enter the character and check whether it is alphabet , uppercase , lowercase etc.

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

char a;

cout<<“Enter the character:”;

cin>>a;

if(a>=’a’&&a<=’z’)

cout<<“Lower case alphabet”;

else

{

if(a>=’A’&&a<=’Z’)

cout<<“Upper Case alphabet”;

else

cout<<“Special Character”;

}

getch();

}

 

 

 

 

 

WAP to print  3 no. and print the 2nd smallest and 2nd greatest.

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

float x, y, z;

cout<<“Enter the three distinct numbers:”;

cin>>x>>y>>z;

if(x>y)

{

if(x>z)

{

if(z>y)

cout<<z<<” is 2nd smallest 2nd greatest”;

else

cout<<y<<” is 2nd greatest 2nd smallest”;

}

else

cout<<x<<” is 2nd smallest and 2nd greatest”;

}

else

{

if(z>y)

cout<<y<<” is 2nd greatest and 2nd smallest”;

else

cout<<z<<” is 2nd greatest and 2nd smallest”;

}

getch();

}

 

 

 

. WAP to enter the grade point and print the grade

0 to 3.3        F

3.3 to 4.5     E

4.5 to 5.9     D

6.0 to 7.5     C

7.6 to 8.9     B

9.0 to 10      A

 

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int s;

char cb;

cout<<“Enter CGPA: “;

cin>>s;

cb=(s>8.9?’A’:(s>7.6?’B’:(s>5.9?’C’:(s>4.5?’D’:(s>3.3?’E’:’F’)))));

cout<<“Grade is: “<<cb;

getch();

}

 

WAP to calculate discount for a snapdeal scheme as given below.

(i)Purchasing for 0 to 5000 10% discount with additional              cash back of 5% for SBI card

(ii)5000 to 10000 15% discount

cb=6.5%

(iii)10000 to 20000 20% discount

cb=10%

(iv)20000 and above 25% discount

cb=12.5%

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int s,cb,sb;

cout<<“enter the amount of goods purchased: “;

cin>>s;

cb=(s>20000?0.25*s:(s>10000?0.2*s:(s>5000?0.15*s:0.1*s)));

cout<<“Casback is: “<<cb;

sb=(s>20000?0.125*s:(s>10000?0.1*s:(s>5000?0.065*s:0.05*s)));

cout<<“\nAdditional cashback for SBI card user:”<<sb;

getch();

}

 

Program of Book Entry Using structure Variable.

 

#include<iostream.h>

#include<stdio.h>

struct books

{

char name[20],author[20];

}a[50];

int main()

{

int i,n;

cout<<“No Of Books[less than 50]:”;

cin>>n;

cout<<“Enter the book details\n”;

cout<<“———————-\n”;

for(i=0;i<n;i++)

{

cout<<“Details of Book No “<<i+1<<“\n”;

cout<<“Book Name :”;

cin>>a[i].name;

cout<<“Book Author :”;

cin>>a[i].author;

cout<<“———————-\n”;

}

cout<<“================================================\n”;

cout<<” S.No\t| Book Name\t|author\n”;

cout<<“=====================================================”;

for(i=0;i<n;i++)

{

cout<<“\n  “<<i+1<<“\t|”<<a[i].name<<“\t| “<<a[i].author;

}

cout<<“\n=================================================”;

return 0;

}

 

WAP to enter a letter and output the next 2 letters.

 

#include <iostream.h>

#include <conio.h>

void main()

{

clrscr();

char charac;

cout <<“Enter your letter : “<< endl;

cin>>charac;

cout <<“The 2 letters are : “<< endl;

cout << (char)(charac-1) << endl;

cout << (char)(charac+1) << endl;

getch();

}

 

 

 

WAP to identify if an input is a symbol, digit or character.

#include <iostream.h>

#include <conio.h>

void main()

{

clrscr();

char charac;

cout <<“Enter your input : “<< endl;

cin>>charac;

if(((charac>=’A’)&&(charac<=’Z’))||((charac>=’a’)&&(charac<=’z’)))

cout <<“Your input “<< charac <<” is a character.”<< endl;

else if((charac>=’0′)&&(charac<=’9′))

cout <<“Your input “<< charac <<” is a digit.”<< endl;

else

cout <<“Your input “<< charac <<” is a symbol.”<< endl;

getch();

}

 

 

WAP to find the total days in the year till date.

 

#include <iostream.h>

#include <conio.h>

void main()

{

clrscr();

int day,month,total;

int days_per_month[12]={31,28,31,30,31,30,31,31,30,31,30,31};

cout <<“Enter the month : “<< endl;

cin>>month;

cout <<“Enter the day : “<< endl;

cin>>day;

total=day;

for(int x=0;x<month-1;x++)

total+=days_per_month[x];

cout <<“The number of days in this year till date = “<< total << endl;

getch();

}

WAP to convert days into years and weeks.

#include <iostream.h>

#include <conio.h>

void main()

{

clrscr();

int days,years,weeks,num1;

cout <<“Enter the number of days : “<< endl;

cin>>days;

years=days/365;

num1=days-(years*365);

weeks=days/7;

num1=days-(weeks*7);

cout << days <<” days = “<< endl;

cout << weeks <<” weeks OR “<< endl;

cout << years <<” years.”<< endl;

getch();

}

 

WAP to convert 2-digit octal number into binary number and print it.

#include <iostream.h>

#include <conio.h>

void octobin(int);

void main()

{

clrscr();

int a;

cout <<“Enter a 2-digit octal number : “;

cin>>a;

octobin(a);

getch();

}

void octobin(int oct)

{

long bnum=0;

int A[6];

int a1,a2,quo,rem;

a2=oct/10;

a1=oct-a2*10;

for(int x=0;x<6;x++)

{

A[x]=0;

}

for (x=0;x<3;x++)

{

quo=a1/2;

rem=a1%2;

A[x]=rem;

a1=quo;

}

for(x=3;x<6;x++)

{

quo=a2/2;

rem=a2%2;

A[x]=rem;

a2=quo;

}

for(x=x-1;x>=0;x–)

{

bnum*=10;

bnum+=A[x];

}

cout <<“The binary number for the octal number “<< oct <<” is “<< bnum <<“.”<< endl;

}

Program to find the sum of each row & column of a matrix of size n x m and if matrix is square, find the sum of the  diagonals also.

#include <iostream.h>

#include <conio.h>

int main()

{clrscr();

int A[10][10],m,n,x,y,sum=0;

cout <<“Enter number of rows and columns in Matrix A : \n”;

cin>>n>>m;

cout <<“Enter elements of Matrix A : \n”;

for(x=1;x<n+1;++x)

for(y=1;y<m+1;++y)

cin>>A[x][y];

for(x=1;x<n+1;++x)

{A[x][m+1]=0;

for(y=1;y<m+1;++y)

A[x][m+1]=A[x][m+1]+A[x][y];}

for(y=1;y<m+1;++y)

{A[n+1][y]=0;

for(x=1;x<n+1;++x)

A[n+1][y]+=A[x][y];

}cout <<“\nMatrix A, Row Sum (Last Column)”<<” and Column Sum (Last Row) : \n”;

for(x=1;x<n+1;++x)

{for(y=1;y<m+2;++y)

cout << A[x][y] <<“”;

cout <<“\n”;}

x=n+1;

for(y=1;y<m+1;++y)

cout << A[x][y] <<“”;

cout <<“\n”;

if(m==n)

{for(x=1;x<m+1;x++)

for(y=1;y<n+1;y++)

if(x==y)

sum+=A[x][y];

else

if(y==m-(x+1))

sum+=A[x][y];}

cout <<“Sum of diagonal elements is : “<< sum << endl;

getch();

return 0;}

Program to enter an integer and print its total value based on the formula

‘x – 1/3!x^3 + 1/5!x^5 – 1/7!x^7 + 1/9!x^9′

 

#include <iostream.h>

#include <conio.h>

#include <math.h>

int main()

{ clrscr();

float factorial=1;

float num,tot,term,total;

int i,n=20,index,j=1;

cout <<“Enter a single-digit integer : \n”;

cin>>num;

tot=num;

total=num;

for(i=2,index=3;i<=n;i++,index+=2)

{ for(j=1,factorial=1;j<=index;j++)

factorial*=j;

tot=tot*pow((double)(-1),(double)(2*i-1))*num*num;

term=tot/factorial;

total+=term;}

cout <<“Total = “<< total << endl;

getch();

return 0;

}

 

Program to enter an integer and output it in the reversed form

#include <iostream.h>

#include <conio.h>

void main()

{

clrscr();

long int num1,num2,rnum=0;

cout <<“Enter an integer : “<< endl;

cin>>num1;

num2=num1;

do

{

rnum=rnum*10;

int digit=num1%10;

rnum+=digit;

num1/=10;

}

while(num1);

cout <<“The integer you typed is “<< num2 <<“.”<< endl;

cout <<“The reversed integer is “<< rnum <<“.”<< endl;

getch();

}

 

Program to find the roots of a quadratic equation

#include <iostream.h>

#include <conio.h>

#include <math.h>

int main()

{

clrscr();

float a,b,c,d,root1,root2;

cout <<“Enter the 3 coefficients a, b, c : “<< endl;

cin>>a>>b>>c;

if(!a){

if(!b)

cout <<“Both a and b cannot be 0 in ax^2 + bx + c = 0″<<“\n”;

else

{

d=-c/b;

cout <<“The solution of the linear equation is : “<< d << endl;

}}

else

{

d=b*b-4*a*c;

if(d>0)

root1=(-b+sqrt(d))/(2*a);

root2=(-b-sqrt(d))/(2*a);

cout <<“The first root = “<< root1 << endl;

cout <<“The second root = “<< root2 << endl;

}

getch();

return 0;

}

Program to enter salary and output income tax and net salary

#include <iostream.h>

#include <conio.h>

void main()

{

clrscr();

int itrate;

float salary,itax,nsalary=0;

cout <<“Enter the salary : “;

cin>>salary;

if(salary>15000)

{

itax=salary*30/100;

itrate=30;

}

else if(salary>=7000)

{

itax=salary*20/100;

itrate=20;

}

else

{

itax=salary*10/100;

itrate=10;

}

nsalary=salary-itax;

cout <<“Salary = $”<< salary << endl;

cout <<“Your income tax @ “<< itrate <<“% = $”<< itax << endl;

cout <<“Your net salary = $”<< nsalary << endl;

getch();

}

Program to count the number of words and characters in a sentence

#include <iostream.h>

#include <conio.h>

void main()

{

clrscr();

int countch=0;

int countwd=1;

cout <<“Enter your sentence in lowercase: “<< endl;

char ch=’a’;

while(ch!=’\r’)

{

ch=getche();

if(ch==”)

countwd++;

else

countch++;

}

cout <<“\n Words = “<< countwd << endl;

cout <<“Characters = “<< countch-1 << endl;

getch();

}

Program to enter the unit reading and output the customer’s telephone bill

#include <iostream.h>

#include <conio.h>

int main()

{

clrscr();

long int units,charge=0;

float total;

const int rent=25;

cout <<“Enter the number of units used : “;

cin>>units;

if(units>200)

charge=(units-200)*20+150*40+50*60;

else if(units>50)

charge=(units-50)*40+50*60;

else

charge=units*60;

total=0.01*charge+rent;

cout <<“You have used “<< units <<” units.”<< endl;

cout <<“Your total telephone bill is $”<< total;

getch();

return 0;

}

Program to enter a string and find its length

#include <iostream.h>

#include <conio.h>

#include <string.h>

void main()

{

clrscr();

int slength;

char x[81]; //Allowing the user to input a maximum of 80 characters.

cout <<“Enter the string : “<< endl;

cin>>x;

slength=strlen(x);

cout <<“The length of the string “<< x <<” is “<< slength <<“.”<< endl;

getch();

}

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s