+ All Categories
Home > Documents > class-11 c++

class-11 c++

Date post: 02-Jun-2018
Category:
Upload: deltaserrapapa
View: 222 times
Download: 0 times
Share this document with a friend

of 79

Transcript
  • 8/10/2019 class-11 c++

    1/79

    OMPUTER S IEN E

    PROGRAMS IN C++

    2011-2012

    NAME: ALOK KUMAR

    ROLL NO: 05

  • 8/10/2019 class-11 c++

    2/79

    1. Program toprint WELCOME IN C++.

    #include

    void main()

    {cout

  • 8/10/2019 class-11 c++

    3/79

    2. Program to find sum of two numbers.

    #include

    void main()

    {

    int num1,num2,sum;

    coutnum1;

    coutnum2;

    sum=num1+num2;

    cout

  • 8/10/2019 class-11 c++

    4/79

    3. Program to find square of a number.

    #include

    void main()

    {int num1,square;

    coutnum1;

    square=num1*num1;

    cout

  • 8/10/2019 class-11 c++

    5/79

    4. Program to check whether a number is greater than or

    less than other number.

    #include

    #include

    void main()

    {

    clrscr();

    int num1,num2;

    cout

  • 8/10/2019 class-11 c++

    6/79

    Enter value for num 1: 5

    Enter value for num 2: 10

    Num1 is smaller than num 2

    5. Program to calculate percentage marks for three

    subjects.

    #include

    void main()

    {

    float English, Maths, Science, Sum, Percentage;

    coutEnglish>>Maths>>Science;

    Sum=English+Maths+Science;

    Percentage=Sum*100/300;cout

  • 8/10/2019 class-11 c++

    7/79

    6. Program that reads temperature in Celsius and displays

    it in Fahrenheit.

    #include

    void main()

    {

    int Celsius, Fahrenheit;

    coutCelsius;

    Fahrenheit=9*Celsius/5+32;

    cout

  • 8/10/2019 class-11 c++

    8/79

    7. Program that reads radius of a circle and prints its area.

    #include

    void main()

    {

    float radius,area;

    coutradius;

    area=radius*3.14*radius;

    cout

  • 8/10/2019 class-11 c++

    9/79

    8. Program that enter value of x from user and prints Y =

    2x and Z = 2x -1.

    #include

    #include

    void main()

    {

    clrscr();

    int x,y,z;

    coutx;

    y=2*x;z=2*x-1;

    cout

  • 8/10/2019 class-11 c++

    10/79

    9. Program to convert a given number of days into years,

    weeks and days.

    #include

    #include

    void main()

    {

    clrscr();

    int totaldays,years,weeks,days,rem1,rem2;

    couttotaldays;

    years=totaldays/365;

    rem1=totaldays%365;

    weeks=rem1/7;

    rem2=rem1%7;

    days=rem2;

    cout

  • 8/10/2019 class-11 c++

    11/79

    Years = 2 weeks = 32 days = 2

    10. Program for swapping of two numbers using thirdnumber.

    #include

    #include

    void main()

    {

    clrscr();

    int a, b, c;

    couta;

    coutb;

    c=a;a=b;

    b=c;

    cout

  • 8/10/2019 class-11 c++

    12/79

    b= 5

    11. Program for swapping of two numbers without usingthird variable.

    #include

    #include

    void main()

    {

    clrscr();

    int a,b;

    couta;

    coutb;

    a=a+b;b=a-b;

    a=a-b;

    cout

  • 8/10/2019 class-11 c++

    13/79

    b= 4

    12. Program to input three numbers and print the largestof three.

    #include

    void main()

    {

    int x,y,z;

    couty>>z;

    if(x>y&&x>z)

    cout

  • 8/10/2019 class-11 c++

    14/79

    9 is greatest

    13. Program to check whether the entered number is oddor even.

    #include

    #include

    void main()

    {

    clrscr();

    int num;

    cout

  • 8/10/2019 class-11 c++

    15/79

    Number is even

    14. Program to find Simple Interest and CompoundInterest.

    #include

    #include

    void main()

    {

    clrscr();

    int P,R,T;

    float SI,CI;

    coutR>>T;

    SI=P*R*T/100;

    CI=P*(1+R/100)^T;cout

  • 8/10/2019 class-11 c++

    16/79

    15. Program to find area of a triangle.

    #include

    #include

    void main()

    {

    clrscr();

    int b, h, area;

    couth;

    area=b*h/2;

    cout

  • 8/10/2019 class-11 c++

    17/79

    16. Program that seeds the name of user and number

    of unit and displays the electricity charge with name.

    The electricity board charges according to following data:

    For first 100 units = 40p/unit

    For next 200 units = 50p/unit

    Beyond 300 units = 60p/unit

    All the users are charged motor charge also which is Rs 50.

    #include

    #include

    #include

    void main()

    {

    clrscr();

    char name[25];

    int unit, charge;

    cout

  • 8/10/2019 class-11 c++

    18/79

    charge=100*40/100+50;

    if(unit>100&&unit300)

    charge=100*40/100+200*50/100+(unit-300)*60/100+50;

    puts(name);

    cout

  • 8/10/2019 class-11 c++

    19/79

    17. Program to enter marks in five subjects and

    calculate percentage. Display grade according to

    following specifications.

    Percentage Grade

    >90 A

    81 B

    71 C

    61 D51 E

    41 F

  • 8/10/2019 class-11 c++

    20/79

    int eng, maths, cs, phy, chem, sum, percentage;

    coutcs>>phy>>chem;

    sum=eng+maths+cs+phy+chem;

    percentage=sum/5;

    cout

  • 8/10/2019 class-11 c++

    21/79

    grade='G';

    cout

  • 8/10/2019 class-11 c++

    22/79

    18. Program that accepts a character between A and J and

    prints next 4 characters.

    #include

    #include

    void main()

    {

    clrscr();

    char ch;

    coutch;

    int num =ch;

    cout

  • 8/10/2019 class-11 c++

    23/79

    19. Program to input a student type (A or B), and for

    A initialize the collage account with Rs 200 otherwise

    initialize the hostel account with Rs 200.

    #include

    void main()

    {

    char stu_type;

    int coll_acc,hostel_acc;

    coutstu_type;

    if(stu_type=='A')

    coll_acc=200;

    cout

  • 8/10/2019 class-11 c++

    24/79

    20. Program that print area for choice 1 and perimeter for

    choice 2 of a circle

    #include

    void main()

    {

    char choice;

    int radius, area, peri;

    coutradius;

    coutchoice;

    area=22*radius*radius/7;

    peri=2*22*radius/7;

    if(choice=='1')cout

  • 8/10/2019 class-11 c++

    25/79

    21. Program to find value of P if P= (w + x)/(y-z). The

    value of w, x, y, z are entered by user.

    #include

    void main()

    {

    float w, x, y, z, P;

    coutw>>x>>y>>z;

    P= (w + x)/(y-z);

    cout

  • 8/10/2019 class-11 c++

    26/79

    22. Program which raise any number x to a positive

    power n.

    #include

    #include

    #include

    void main()

    {

    clrscr();

    long double x,n,p;

    coutx;

    coutn;p=pow(x,n);

    cout

  • 8/10/2019 class-11 c++

    27/79

    23. Program to calculate commission for the salesmen the

    commission is calculated according to following rates.

    Sales Commission rate

    30001 onwards 15%

    2200030000 10%

    1200122000 7%

    500112000 3%

    05000 0%

    #include

    #include

    void main()

    {clrscr();

    float sales;

    coutsales;

    if(sales>5000)

    if(sales

  • 8/10/2019 class-11 c++

    28/79

    else

    cout

  • 8/10/2019 class-11 c++

    29/79

    24. Program to print whether the entered character is an

    uppercase or a lowercase character or a digit or any other

    character. The ASCII codes are given below.

    Characters ASCII Range

    0 9 4857

    A Z 6590

    a z 97 - 122

    #include

    #include

    void main()

    {

    clrscr();

    char ch;

    int num;

    coutch;

    num=ch;

    if(num>=48)

    if(num>=65)

    if(num>=97&&num

  • 8/10/2019 class-11 c++

    30/79

    else

    cout

  • 8/10/2019 class-11 c++

    31/79

    #include

    #include

    void main()

    {

    clrscr();

    int n,i;

    coutn;

    for(i=1;i

  • 8/10/2019 class-11 c++

    32/79

    #include

    #include

    #include

    void main()

    {

    clrscr();

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

    cout>a>>b>>c;

    if(a==0)

    cout

  • 8/10/2019 class-11 c++

    33/79

    else if(delta==0)

    {

    root1=root2=-b/(2*a);

    cout

  • 8/10/2019 class-11 c++

    34/79

    #include

    #include

    #include

    void main()

    {

    clrscr();

    int n,i;

    coutn;

    for(i=2;i

  • 8/10/2019 class-11 c++

    35/79

    #include

    #include

    #include

    void main()

    {

    clrscr();

    int j,i;

    for(i=0;i

  • 8/10/2019 class-11 c++

    36/79

    #include

    #include

    void main()

    {

    clrscr();

    int i, n, sum=0;

    coutn;

    for(i=1;i

  • 8/10/2019 class-11 c++

    37/79

    #include

    void main()

    {

    int n,i,sum1=0,sum2=0;

    coutn;

    for(i=1;i

  • 8/10/2019 class-11 c++

    38/79

    #include

    #include

    void main()

    {

    clrscr();

    int i,j;

    for(i=1;i

  • 8/10/2019 class-11 c++

    39/79

    #include

    #include

    void main()

    {

    clrscr();

    int i,j;

    for(i=1;i

  • 8/10/2019 class-11 c++

    40/79

    #include

    #include

    void main()

    {

    clrscr();

    int i;

    for(i=1;i

  • 8/10/2019 class-11 c++

    41/79

    #include

    void main()

    {

    int i, j, k, n;

    coutn;

    for(i=1;i

  • 8/10/2019 class-11 c++

    42/79

    #include

    #include

    void main()

    {

    clrscr();

    int i, n, facto=1;

    coutn;

    for(i=1;i

  • 8/10/2019 class-11 c++

    43/79

    #include

    void main()

    {

    char ch;

    int i=ch, j, n;

    coutn;

    for(i=65;i

  • 8/10/2019 class-11 c++

    44/79

    void main()

    {

    int i, j, k, n;

    coutn;

    for(i=1;i

  • 8/10/2019 class-11 c++

    45/79

    #include

    void main()

    {

    int n, n1, n2=n, rev=0;

    coutn;

    while(n)

    {n1=n%10;

    rev=rev*10+n1;

    n=n/10;

    }

    if(n2==rev)

    cout

  • 8/10/2019 class-11 c++

    46/79

    #include

    #include

    void main()

    {

    char ch;

    coutch;

    if(isalpha(ch))

    cout

  • 8/10/2019 class-11 c++

    47/79

    #include

    void main()

    { char ch;

    coutch;

    if(isalpha(ch))

    { cout

  • 8/10/2019 class-11 c++

    48/79

    #include

    void main()

    {

    char s1[10], s2[10];

    cout

  • 8/10/2019 class-11 c++

    49/79

    void main()

    {

    int n=1;

    char str[100];

    cout

  • 8/10/2019 class-11 c++

    50/79

    { char str[25];

    cout

  • 8/10/2019 class-11 c++

    51/79

    int len, i, f=1;

    cout

  • 8/10/2019 class-11 c++

    52/79

    void main()

    { clrscr();

    char str[20], ch;

    int i, f=0;

    cout

  • 8/10/2019 class-11 c++

    53/79

    OUTPUT

    Enter string: My name is Khan and I am not a terrorist.

    Enter character: K

    The given character is present in the string

    The position of the character is: 12

    Enter character: t

    The given character is present in the string

    The position of the character is: 32

    46. Program to find cube of a number (using

    function).

    #include

    int cube(int);

    void main()

    {

    int a,c;

    cout

  • 8/10/2019 class-11 c++

    54/79

    cin>>a;

    c=cube(a);

    cout

  • 8/10/2019 class-11 c++

    55/79

    clrscr();

    int n;

    even_odd(n);

    }

    void even_odd(int n)

    {

    int maxeven=0, maxodd=0;

    while(n)

    {

    coutn;

    if(n%2==0)

    {

    if(n>maxeven)maxeven=n;

    }

    else if(n%2==1)

    {

    if(n>maxodd)

    maxodd=n;

    }

    else if(n==0)

    break;

  • 8/10/2019 class-11 c++

    56/79

    }

    cout

  • 8/10/2019 class-11 c++

    57/79

    void factorial(int n)

    { int fact=1;

    int i;

    for(i=1; i

  • 8/10/2019 class-11 c++

    58/79

    { coutn;

    if(n>large)

    large=n;

    coutans;

    }

    cout>f;

    greatest(d, e, f);

    }

    void greatest(int d, int e, int f)

  • 8/10/2019 class-11 c++

    59/79

    { if(d>e && d>f)

    coutf)

    coute)

    cout

  • 8/10/2019 class-11 c++

    60/79

    { if(v[i]>large)

    large=v[i];

    else if(v[i]

  • 8/10/2019 class-11 c++

    61/79

    { int temp;

    temp =c;

    c=d;

    d=temp;

    cout

  • 8/10/2019 class-11 c++

    62/79

    }

    int sum(int n1)

    { int p=0;

    while(n1)

    { p=p+(n1%10);

    n1=n1/10;

    }

    return p;

    }

    OUTPUT

    Enter number:356

    Sum of digits : 14

    54. Program to print all those elements of a matrix that are

    on and are on the right side of main diagonal.

    #include

    void main()

    {int arr[3][3];

    cout

  • 8/10/2019 class-11 c++

    63/79

    { if(i

  • 8/10/2019 class-11 c++

    64/79

    void negative(int arr1[], int size1)

    { for(int i=0; i

  • 8/10/2019 class-11 c++

    65/79

    { if(i+j>4)

    arr1[i][j]=0; }

    for(i=0;i

  • 8/10/2019 class-11 c++

    66/79

    for(j=0; j

  • 8/10/2019 class-11 c++

    67/79

    cin>>B[j];

    for(i=0,k=0; i

  • 8/10/2019 class-11 c++

    68/79

    coutn;

    for(i=0; i

  • 8/10/2019 class-11 c++

    69/79

    }

    }

    cout

  • 8/10/2019 class-11 c++

    70/79

    for(i=0; i

  • 8/10/2019 class-11 c++

    71/79

    for(int j=0; j>A[i][j];

    }

    cout

  • 8/10/2019 class-11 c++

    72/79

    }

    OUTPUT

    Enter matrix A: 1 2 1

    2 1 2

    1 2 1

    Enter matrix B: 2 1 2

    1 2 1

    2 1 2

    Matrix A matrix B:

    5 8 5

    10 4 10

    5 8 5

    62. Program to delete duplicate elements of an array

    with 0 and take all 0 to right.

    #include

    void main()

    { int A[10];

    cout

  • 8/10/2019 class-11 c++

    73/79

    { for(int j=i+1; A[j]!='\0'; j++)

    { if(A[i]==A[j])

    { for(int k=j; A[k]!='\0'; k++)

    A[k]=A[k+1]; }

    }}

    for(i=0; A[i]!='\0'; i++)

    { if(A[i]==0)

    A[i]='\0'; }

    cout

  • 8/10/2019 class-11 c++

    74/79

    {

    char cname[20];

    int ccode;

    int cday;

    int cmonth;

    int cyear;

    int irate;

    int totalamount;

    int tot_years;

    };

    clients c[50];

    void main()

    {

    clrscr();float ci[50];

    for(int i=0; i>c[i].ccode;

    cin>>c[i].cday;

    cin>>c[i].cmonth;

    cin>>c[i].cyear;

    cin>>c[i].tot_years;

  • 8/10/2019 class-11 c++

    75/79

    cin>>c[i].irate;

    cin>>c[i].totalamount;

    }

    for (i=0; i

  • 8/10/2019 class-11 c++

    76/79

    int eno;

    char ename[20];

    char eaddress[20];

    }e[10];

    void main()

    {

    clrscr();

    int i,n;

    char ans='y';

    for(i=0;i>e[i].eno;

    gets(e[i].ename);

    gets(e[i].eaddress);do{

    coutn;

    if(n==e[i].eno)

    {

    cout

  • 8/10/2019 class-11 c++

    77/79

    coutans;

    }

    while(ans=='y');

    }

    }

    65. Program to create an array containing details of

    25 students (including Roll number, name, marks inthree subjects) and print out a list of students who

    have failed in more than 1 subject. Assume 40%

    marks as pass marks.

    #include

    #include

    #includestruct student

    { int rno;

    char name[20];

  • 8/10/2019 class-11 c++

    78/79

    int sub1;

    int sub2;

    int sub3;

    }s[25];

    void main()

    {

    for(int i=0;i>s[i].sub3;}

    cout

  • 8/10/2019 class-11 c++

    79/79

    if(s[i].sub31)

    {

    puts(s[i].name)

    cout


Recommended