Computer Project File

33
1. Write a Program to display ASCII code of character. #include<iostream.h> #include<conio.h> void main( ) { clrscr( ); char a; int b; cout<<”Enter a character”; cin>>a; b=a; cout<<”ASCII code is”<<b; getch( ); } OUTPUT- Enter a character A ASCII code is 65

Transcript of Computer Project File

Page 1: Computer Project File

1. Write a Program to display ASCII code of character.

#include<iostream.h>#include<conio.h>void main( ){clrscr( );

char a;int b;cout<<”Enter a character”;cin>>a;b=a;cout<<”ASCII code is”<<b;getch( );}

OUTPUT-Enter a character AASCII code is 65

Page 2: Computer Project File

2. Write a program to convert a given number of days into years, weeks and days.

#include<iostream.h>#include<conio.h>void main( ){clrscr( );int d,w,y,e;cout<<”Enter number of days”<<”\n”;cin>>d;y=d/365;w=(d%365)/7;e=(d%365)%7;cout<<”\n”<<y<<”years”,<<w<<”weeks,<<e<<”days”;getch( );}

OUTPUT-Enter number of days 5651year,28weeks,4days

Page 3: Computer Project File

3. Write a program to input principal, rate and time and calculate SI. If time is more than 10 years calculate SI with 10% interest otherwise with 8%interest.

#include<iostream.h>#include<conio.h>void main( ){clrscr( );int p,t,sia,sib;cout<<”Enter Principal and Time”;cin<<p<<t;if (t>0){sia=(p*t*8)/100;cout<<”\n”<<SI is<<sia;}else{sib=(p*t*10)/100;cout<<”\n”<<SI is<<sib;}getch( );}

OUTPUT-Enter Principal and Time 100 11SI is 110

Page 4: Computer Project File

4. Write a program to input a number. If the number is even print its square otherwise print its cube.

#include<iostream.h>#include<conio.h>void main( ){clrscr( );int a;cout<<”Enter a number”;cin>>a;if (a%2= =0)cout<<a*a;elsecout<<a*a*a;}getch( );}

OUTPUT-

Enter a number 5125

Page 5: Computer Project File

5. Write a program to input a number. If it is odd and positive print its square root otherwise print n5

#include<iostream.h>#include<conio.h>void main( ){clrscr( );int a;cout<<”Enter a number”;cin>>a;if (a>0 && a%2!=0)cout<<sqrt(a);else{cout<<a*a*a*a*a;}getch( );}

OUTPUT-Enter a number 232

Page 6: Computer Project File

6. Write a program to input age of a person. If age>=18 print ‘You can vote’ otherwise print ‘You cannot vote’.

#include<iostream.h>#include<conio.h>void main( ){clrscr( );int age;cout<<”Enter your age \n”;cin>>age;(age>=18)?cout<<”You can vote”; : cout <<”You cannot vote”;getch( );}

OUTPUT-Enter your age 17You cannot vote

Page 7: Computer Project File

7. Write a program for temperature conversion menu that gives the user the option of converting temperature from Fahrenheit to Celsius or Celsius to Fahrenheit depending upon the user’s choice.

#include<iostream.h>#include<conio.h>void main( ){clrscr( );int a;float c,f;cout<<”Choose your operation\n"cout<<"1. Celsius to Fahrenheit;cout<<"2. Fahrenheit to Celsius;cin>>a;if (a= =1){cout<<"Enter temperature in Celsius \n";cin>>c;f=(c*1.8)+32;cout<<"Temperature in Fahrenheit is"<<f;}else{cout<<"Enter temperature in Fahrenheitcin>>c;f=(c-32)/1.8;cout<<"Temperature in Celsius is<<f;}getch( );}

OUTPUT-Choose your operation 1Enter temperature in Celsius 10Temperature in Fahrenheit is 40

Page 8: Computer Project File

8. Write a program to check whether a given year is a leap year or not.

#include<iostream.h>#include<conio.h>void main( ){clrscr( );int a;cout<<"Enter year";cin>>a;if (a%4==0)cout<<"It is a leap year"'elsecout<<"It is not a leap year";getch( );}

OUTPUTEnter year 1992It is a leap year

Page 9: Computer Project File

9. Write a program to calculate commission for the salesman. The commission is to be calculated at the following rates

SALES COMMISSION RATE

30001 onwards 15%22001-30000 10%12001-22000 7%5001-42000 3%

0-5000 0%

#include<iostream.h>#include<conio.h>void main( ){clrscr( );int a,c;cout<<"Enter sales\n";cin>>a;{if(a>=0 && a<=5000)cout<<"no commission";}else if(a>=5001 && a<=12000){c=a*0.03; cout<<"Your commission is"<<c;} else if(a>=12001 && a<=22000){c=a*0.07; cout<<"Your commission is"<<c;}else if(a>=22001 && a<=30000){c=a*0.10; cout<<"Your commission is"<<c;}else if(a>=30001){c=a*0.15; cout<<"Your commission is"<<c;}getch( );}OUTPUTEnter Sales 30000Your commission is 3000

Page 10: Computer Project File

10.Write a program to input a day number and translate into name of day.

#include<iostream.h>#include<conio.h>void main( ){clrscr( );int a;cout<<"Enter day number";cin>>a;switch(a){case1: cout<<"Sunday";break;case2: cout<<"Monday";break;case3: cout<<"Tuesday ";break;case4: cout<<"Wednesday";break;case5: cout<<"Thursday";break;case6: cout<<"Friday";break;case7: cout<<"Saturday";break;}getch( );}

OUTPUTEnter day number 1Sunday

Page 11: Computer Project File

11.Write a program to find factorial of a number

#include<iostream.h>#include<conio.h>void main( ){clrscr( );int num;long int fact=1;cout<<"Enter a number";cin>>num;while(num>=1){fact=fact*num;num--;}cout <<"Factorial of number entered is"<<fact;getch( );}

OUTPUTEnter a number 5Factorial of number entered is 120

Page 12: Computer Project File

12.Write a program to print 1 2 4 8 16 32 64 128

#include<iostream.h>#include<conio.h>#include<math.h>

void main( ){clrscr( );int a=0, b;while(a<=7){b=pow(2,a);cout<<b;a++;}getch( );}

OUTPUT1 2 4 8 16 32 64 126

Page 13: Computer Project File

13.Write a program to generate Fibonacci sequence till 15 elements

#include<iostream.h>#include<conio.h>void main( ){clrscr( );int a=1, i=0, j=1, k;cout<<I;cout j;{while (a<=13)k=i+j;cout<<k;i-j;j=k;i++;}getch( );}

OUTPUT0 1 1 2 3 5 8 13 21 34 55 89 144 233 377

Page 14: Computer Project File

14.Write a program to print all even numbers between 1 and 50 in reverse order

#include<iostream.h>#include<conio.h>void main( ){clrscr( );i=50;do{cout<<i;i=i-2}while(i>=1)getch( );}

OUTPUT48 46 44 42 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2

Page 15: Computer Project File

15.Write a program to print the sum of first 10 natural numbers

#include<iostream.h>#include<conio.h>void main( ){clrscr( );int i=1, sum=0;do{Sum=sum+i;i++}while(i<=10)getch( );}

OUTPUT55

Page 16: Computer Project File

16.Write a program to print 112123123412345

#include<iostream.h>#include<conio.h>void main( ){clrscr( );int i, j;for (i=1;i<=5;i++){cout<<"\n";for (j=1; j<=5; j++){cout<<j;}}getch( );}

OUTPUT-112123123412345

Page 17: Computer Project File

17.Write a program to print**********

#include<iostream.h>#include<conio.h>void main( ){clrscr( );int i, j;for (i=1;i<=4;i++){cout<<"\n";for (j=1; j<=1; j++){cout<<"*";}}getch( );}

OUTPUT

**********

Page 18: Computer Project File

18.Write a program to printAABABCABCD

#include<iostream.h>#include<conio.h>void main( ){clrscr( );char ch='A';int i, j;for (i=65;i<=68;i++){cout<<"\n";for (j=ch; j<=i; j++){cout<<char j;}}getch( );}

OUTPUT

AABABCABCD

Page 19: Computer Project File

19.Write a program to input a character and change its case

#include<iostream.h>#include<conio.h>void main( ){clrscr( );char ch;do{cout<<"Enter a character";cin>>ch;if(ch= ='\n'){ch=getchar();}Elseif(ch>=65 && ch<=90)ch=ch+32;Else if (ch>=97 && ch<=122)ch=ch-32;char (ch);}while (ch!='0')getch( );}

OUTPUT

Enter a character Aa

Page 20: Computer Project File

20. Write a program to count the no. of characters entered.

#include<iostream.h>#include<conio.h>void main( ){clrscr( );char ch;int a;cout <<"Enter the characters:";cin.get(ch);while(ch!="\n"){a++;}cout.put(ch);getch( );}

OUTPUTEnter the characters: pearl5

Page 21: Computer Project File

21.Write a program to find the cube of a number

#include<iostream.h>#include<conio.h>void main( ){clrscr( );float cube(float);float x,y;cout<<"\n Enter the number whose cube is to be calculated:;cin>>x;y=cube(x);cout <<"\n The cube of"<<x<<"is"<<y<<"\n";getch( );return 0;}float cube(float a){float n ;n=a*a*a;return(n);}

OUTPUT

Enter the number whose cube is to be calculated:9The cube of 9 is 729

Page 22: Computer Project File

22.Write a program to swap two values

#include<iostream.h>#include<conio.h>void main( ){clrscr( );void swap(int &, int&) ;int a,b;a=7;b=4cout<<"\n The original values are:a="<<a<<",b="<<b<<"\n";swap(a,b);cout <<"The new values are:a="<<a<<",b="<<b<<"\n"; getch( );return 0;}void swap(int &x, int&y){int temp;temp=x;x=y;y=temp;}getch( );}

OUTPUT

The original values are:a=7,b=4The new values are:a=4,b=7

Page 23: Computer Project File

23.Write a program to read marks of 50 students and store them under an array.

#include<iostream.h>#include<conio.h>int main( ){const int size=50;float marks [size];for (int i=0; i<size; i++){cout<<"Enter marks of student"<<i+1<<"\n";cin>>marks[i];}cout<<"\n";for(i=0; i<size; i++)cout<< "Marks [" <<i+1<< "]="<<marks[i]<<"\n";return 0;}

OUTPUT

Enter marks of student 195Enter marks of student 274Enter marks of student 389Marks[1]=95Marks[2]=74Marks[3]=89

Page 24: Computer Project File

24.Write a program to replace every space in a string with a tilde.

#include<iostream.h>#include<conio.h>#include<string.h>int main( ){clrscr();char string[81];cout<<"Enter string(max 80 characters)\n";cin.getline(string, 81);int x1 = strlen(string);for(int i=0; string[i]!='\0'; i++)if(string[i]==' ')sting[i]= ' ~ ';cout<<"The changed string is \n";cout.write(string,x1);return 0 ;}

OUTPUTEnter string(max 80 characters)My name is Pearl.The changed string isMy~name~is~Pearl.

Page 25: Computer Project File

25.Write a program to reverse words of a string individually.

#include<iostream.h>#include<conio.h>#include<string.h>#include<stdio.h>

void main( ){clrscr( );int l,I,k=0;char str[81], word[81];cout<<"Enter string(max 80 characters)\n";gets(str);strcat(str, " ");for(i=0; str{i} !='\0' ;i++){if( str [i] !=' '){word[k]=str[i];k=k+1;}else{while (k>0){cout<<word[--k];}cout str[i];}}getch( );}

OUTPUTEnter string(max 80 characters): I am PearlI ma lraeP

Page 26: Computer Project File

INDEXS.No. Title Page No.1 Program to display ASCII code of character 12 Program to convert a given number of days into

years, weeks and days2

3 Program to input principal, rate and time and calculate SI

3

4 Pr Program to input a number. If the number is even prprint its square otherwise print its cube.

4

5 Program to input a number. If it is odd and positive print its square root otherwise print n5

5

6 Program to input age of a person. If age>=18 print ‘You can vote’ otherwise print ‘You cannot vote’

6

7 Program for temperature conversion menu that gives the user the option of converting temperature from Fahrenheit to Celsius or Celsius to Fahrenheit

7

8 Program to check whether a given year is a leap year or not

8

9 Program to calculate commission for the salesman 910 Program to input a day number and translate into

name of day10

11 Program to find factorial of a number 1112 Program to print 1 2 4 8 16 32 64 128 1213 Program to generate Fibonacci sequence till 15

elements13

14 1. Program to print all even numbers between 1 and 50 in reverse order

14

15 Program to print the sum of first 10 natural numbers 1516 2. Program to print

112123123412345

16

17 3. Program to print******

17

Page 27: Computer Project File

****

18 4. Program to printAABABCABCD

18

19 Program to input a character and change its case 1920 Program to count the no. of characters entered 2021 Program to find the cube of a number 2122 Program to swap two values 2223 Program to read marks of 50 students and store them

under an array.23

24 Program to replace every space in a string with a tilde 2425 Program to reverse words of a string individually 25