Programs of File

Embed Size (px)

Citation preview

  • 8/8/2019 Programs of File

    1/38

    PROG 1:-Write a program to find the power ofthe number.

    #include

    #includedouble pow(double ,int );void main(){double n,r;clrscr();

    int p;char c;

    coutn;do{

    coutc; if(c=='y')

    {

    coutp;r=pow(n,p);

    }else{

    if(c=='n'){

    p=2;r=pow(n,p);cout

  • 8/8/2019 Programs of File

    2/38

    }} while(c!='y' && c!='n');

    getch();

    }

    double pow(double n,int p){

    double r=1; int i; if(p

  • 8/8/2019 Programs of File

    3/38

    PROG 2:-write a program using structure

    #include

    #includestruct point{int x;int y;}p[2],pt={0,0};void main()

    {int i;for(i=0;i

  • 8/8/2019 Programs of File

    4/38

    Output:-

    enter x0and y coordinate03 4

    enter x1and y coordinate16 7

    sum of x coordinate is9

    sum of y coordinate is11

  • 8/8/2019 Programs of File

    5/38

    PROG 3:- WAP TO PERFORMaddtion,subtraction,multiply and divison.

    #include#includevoid main(){double operand1;double operand2;char c,x;do

    {coutoperand1>>x>>operand2;switch(x){ case'+':cout

  • 8/8/2019 Programs of File

    6/38

    cout

  • 8/8/2019 Programs of File

    7/38

    PROG 4:-WRITE A PROGRAM USING STRUCTURE

    #include#includestruct phone{ char area[10]; char exchange[10]; char phno[10];

    };void main(){phone p1={"212","767","89000"};phone p2;coutp2.area>>p2.exchange>>p2.phno;cout

  • 8/8/2019 Programs of File

    8/38

    OUTPUT:-

    enter your phone no.

    344 321 44444

    my phoneno is

    21276789000

    your phoneno is

    34432144444

  • 8/8/2019 Programs of File

    9/38

    PROG 5:-WRITE A PROGRAM A HOTDOG STAND THAT

    ENABLES THREE KINDS OF ITERATION.

    #include#includeclass hotdogsand{private: int hotdog_one_hand;

    int buns_one_hand;public: void display()

    {cout

  • 8/8/2019 Programs of File

    10/38

    hotdogsand stand1;hotdogsand stand2;hotdogsand stand3;clrscr();

    cout

  • 8/8/2019 Programs of File

    11/38

  • 8/8/2019 Programs of File

    12/38

    enter the buns on hand

    87

    enter the choice of stand

    q

    display the value of stand1

    2354

    display the value of stand2

    7654

    display the value of stand3

    3287

  • 8/8/2019 Programs of File

    13/38

    PROG 6:-WRITE A PROGRAM TO READ THE DATA OFN NO. OF THE EMPLOYEE AND COMPUTE THE NETSALARY.#include

    #includeclass employee{private: int empno; char empname[20]; int bs; int da;

    int incometax; int ns;public:void getdata(){coutempno;coutname;

    coutbasicsalary;

    }void display(){cout

  • 8/8/2019 Programs of File

    14/38

    }}void main(){

    employee x[5];int i;clrscr();for(i=1;i

  • 8/8/2019 Programs of File

    15/38

    12999name of the employee iskanchannumber of employee is12net salary of employee is

    0name of the employee isjuhinumber of employee is14net salary of employee is0

    PROG 7:- WRITE A PROGRAM TO CREATE AFANCY_TEXT OBJECT AND GAVE IT TEXTGONE WITH

    WITH WIND THEN IT DISPLAY IT TEXT USING

    THREE DIFFERENT VERSION OF BOX_DISPLAY().

    #include#include#includeconstint Maxlength=40;

  • 8/8/2019 Programs of File

    16/38

    class fancy_text{private:char text[Maxlength];

    public:void set_text(char tx[]){strcpy(text,tx);}void box_display();void box_display(char);void box_display(char, int);

    };void fancy_text::box_display(){cout

  • 8/8/2019 Programs of File

    17/38

    cout

  • 8/8/2019 Programs of File

    18/38

    private:char text[Maxlength];public:void set_text(char tx[])

    {strcpy(text,tx);}void box_display(char ch ='-', int n=18){int m;for(m=0;m

  • 8/8/2019 Programs of File

    19/38

    PROG 9:-WRITE A PROGRAM TO CREATE FUNCTIONARGUMENTS.

    #include#include#includeclass airtime{int hours;

  • 8/8/2019 Programs of File

    20/38

    int mins;public: void set()

    {

    char dummy;couthours>>dummy>>mins;

    } void display()

    {

    cout

  • 8/8/2019 Programs of File

    21/38

    t1.set();cout

  • 8/8/2019 Programs of File

    22/38

    class omega{private:int intvar;

    public:omega(int v){intvar=v;}omega(const omega&om){intvar=om.intvar;

    cout

  • 8/8/2019 Programs of File

    23/38

    parent(){cout

  • 8/8/2019 Programs of File

    24/38

    child constructorterminatingchild destructorparent destructor

    PROG 12:-WRITE A PROGRAM TO CREATE A CLASSTHE MODULES DISTANCE IN FEET AND INCHES.

    #include#includeclass english{private:

  • 8/8/2019 Programs of File

    25/38

    int feet;float inch;public:english()

    {feet=0;inch=0.0;}english(float metres){const float mt=3.280883;float ft=mt*metres;

    feet= int(ft);inch= 12*(ft-feet);}english(int f, float i){feet=f;inch=i;}void display()

    {cout

  • 8/8/2019 Programs of File

    26/38

    cout

  • 8/8/2019 Programs of File

    27/38

    {private:char ename[20];int esno ;

    public :void input(){coutename;cout>esno;

    }void output(){cout

  • 8/8/2019 Programs of File

    28/38

    swap(e1,e2);cout

  • 8/8/2019 Programs of File

    29/38

    int number;public: void getdata()

    {

    coutname;coutnumber;}

    void putdata(){cout

  • 8/8/2019 Programs of File

    30/38

    };class scientist:public employee{private:

    char publis[20];public:void getdata(){employee::getdata();coutpublis;

    }

    void putdata(){employee::putdata();cout

  • 8/8/2019 Programs of File

    31/38

    l1.getdata();cout

  • 8/8/2019 Programs of File

    32/38

    publisgdfoutput the object l1 of the classlabourname=juhinumber=15

    Prog 15:-write a program using static datamember.

    #include#includeclass shared{static int a;

  • 8/8/2019 Programs of File

    33/38

    int b;public:

    void set(int i,int j){

    a=i;b=j;

    }void show();

    };int shared::a;void shared::show(){

    cout

  • 8/8/2019 Programs of File

    34/38

    this is static a:2this is static b:2

    this is static a:2

    this is static b:1

    prog 16:-write a program using staticmembetr function.

    #include#includeclass c1{static int resources;

  • 8/8/2019 Programs of File

    35/38

    public:static int get_resources();void free_resources(){

    resources=0;}

    };int c1::resources;int c1::get_resources(){if(resources)return 0;

    elsereturn 1;}void main(){clrscr();c1 ob1,ob2;if(c1::get_resources());cout

  • 8/8/2019 Programs of File

    36/38

  • 8/8/2019 Programs of File

    37/38

  • 8/8/2019 Programs of File

    38/38