1 (1)jjk

Embed Size (px)

Citation preview

  • 8/13/2019 1 (1)jjk

    1/34

    1.Banking Program

    #include

    #include

    using namespace std;

    class bankaccount {

    public: char name[20];

    long accno;

    int acctype;

    double balance;

    int assign();

    int deposit();

    int withdraw();

    int display();

    };

    int main() {

    bankaccount obj;

    int bankaccount::assign() {

    cout

  • 8/13/2019 1 (1)jjk

    2/34

    cin>>obj.accno>>obj.acctype;

    balance=0.0;

    }

    int bankaccount::deposit() {

    coutobj.balance;

    }

    int bankaccount::withdraw() {

    cout

  • 8/13/2019 1 (1)jjk

    3/34

    void main()

    {

    int Number,Temp,b=0;

    cout

  • 8/13/2019 1 (1)jjk

    4/34

    {

    clrscr();

    long int n,rev=0,m,num;

    coutn;

    num=n;

    while(n>0)

    {

    m=n%10;

    rev=rev*10+m;

    n=n/10;

    }

    cout

  • 8/13/2019 1 (1)jjk

    5/34

    void main()

    {

    clrscr();

    cout

  • 8/13/2019 1 (1)jjk

    6/34

    using namespace std;

    class data

    {

    int a,b;

    public:

    int sum;

    void getdata(int a,int b);

    void display();

    };

    void data::display()

    {

    cout

  • 8/13/2019 1 (1)jjk

    7/34

    6.to check whether a number is strong or not

    #include

    int main(){

    int num,i,f,r,sum=0,temp;

    cout > num;

    temp=num;

    while(num){

    i=1,f=1;

    r=num%10;

    while(i

  • 8/13/2019 1 (1)jjk

    8/34

    return 0;

    }

    7a)Swap numbers using call by reference

    #includevoid swap(int &iNum1, int &iNum2);void main(){int iVar1, iVar2;coutiVar2;swap(iVar1, iVar2);cout

  • 8/13/2019 1 (1)jjk

    9/34

    #include

    using namespace std;

    long add(long, long);

    float add(float, float);

    int main()

    {

    long a, b, x;

    float c, d, y;

    cout > a >> b;

    x = add(a, b);

    cout d;

    y = add(c, d);

    cout

  • 8/13/2019 1 (1)jjk

    10/34

    return 0;

    }

    long add(long x, long y)

    {

    long sum;

    sum = x + y;

    return sum;

    }

    float add(float x, float y)

    {

    float sum;

    sum = x + y;

    return sum;

    }

    9. To swap private member values of class by using friend function

    #include

    #include

    class XYZ;

    class ABC;

    {

  • 8/13/2019 1 (1)jjk

    11/34

    int a;

    public;

    void setdata(int m)

    {

    a=m;

    }

    Friend void exchange(ABC & X,XYZ &W);

    void display data()

    {

    cout

  • 8/13/2019 1 (1)jjk

    12/34

    void exchange(ABC & value 1,XYZ & value 2)

    {

    int temp;

    temp=value 1.a;

    value 1.a=value 2.b;

    value 2.b=temp;

    };

    void main()

    {

    ABC m;

    m.setdata(10);

    XYZ n;

    n.setdata(20);

    cout

  • 8/13/2019 1 (1)jjk

    13/34

    int sold;

    int left;

    static int total;

    public:

    void sold_items()

    {

    cout

  • 8/13/2019 1 (1)jjk

    14/34

    items.stock_remaining();

    items.display();

    return 0;

    }

    11.write the same program without using static members

    #include

    using namespace std;

    class shop

    {int sold;

    int left;

    int total;

    public:

    void sold_items()

    {

    cout

  • 8/13/2019 1 (1)jjk

    15/34

    }

    };int main()

    {

    shop items;

    items.sold_items();

    items.stock_remaining();

    items.display();

    return 0;

    }

    12. To check whether a string is palindrome or not

    #include

    #include

    using namespace std;

    int main()

    {

    char str[100];

    cout > str;

    int x = strlen(str)-1;

    for(int i = 0; i

  • 8/13/2019 1 (1)jjk

    16/34

    }

    else

    {

    cout

  • 8/13/2019 1 (1)jjk

    17/34

    int age;

    void getdata();

    };

    class salary : public employee

    {

    double basic;

    double allowance;

    double bonus;

    public :

    //void get();

    void display();

    double tot();

    };

    void employee ::

  • 8/13/2019 1 (1)jjk

    18/34

    getdata()

    {

    cout name;

    cout yoj;

    cout age;

    }

    void salary :: display()

    {

    double sal = tot();

    cout

  • 8/13/2019 1 (1)jjk

    19/34

    {

    cout basic;

    cout allowance;

    cout bonus ;

    double sum = basic + allowance + bonus ;

    return sum;

    }

    int main()

    {

    salary s;

    s.getdata();

    s.display();

  • 8/13/2019 1 (1)jjk

    20/34

    return 0;

    }

    14.To construct a pattern

    #include

    using namespace std;

    int main()

    {

    char c='A';

    for(int i=1;ii;j--)

    cout

  • 8/13/2019 1 (1)jjk

    21/34

    c++;

    }

    cout

  • 8/13/2019 1 (1)jjk

    22/34

    {

    if(s[j]==s[i])

    {

    for(int k=j;k

  • 8/13/2019 1 (1)jjk

    23/34

    int i, k = 0, l = 0;

    while (k < m && l < n)

    {

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

    {

    cout

  • 8/13/2019 1 (1)jjk

    24/34

    {

    for (i = n-1; i >= l; --i)

    {

    cout= k; --i)

    {

    cout

  • 8/13/2019 1 (1)jjk

    25/34

    }

    }

    }

    int main()

    {

    i

    nt a[R][C] = { {1, 2, 3, 4, 5, 6},

    {7, 8, 9, 10, 11, 12},

    {13, 14, 15, 16, 17, 18}

    };

    spiralPrint(R, C, a);

    return 0;

    }

    17.To print pattern 2

    #include

    using namespace std;

    int main()

  • 8/13/2019 1 (1)jjk

    26/34

    {

    char c='A';

    for(int i=1;ii;j--)

    cout

  • 8/13/2019 1 (1)jjk

    27/34

    return 0;

    }

    18. //WAP to print student's status of academic and sport activities by forming the three classes

    namely student, sports. Use multiple inheritance and assume the required data.

    #include

    #include

    using namespace std;

    class acad

    {

    public:

    string branch;

    float cg;

    void getdata();

    };

    class sport

  • 8/13/2019 1 (1)jjk

    28/34

    {

    public :

    string sport;

    int year;

    void get();

    };

    class student :public acad, public sport

    {

    string name = "saurabh";

    public :

    void display();

    };

    void acad :: getdata()

    {

  • 8/13/2019 1 (1)jjk

    29/34

    cout branch;

    cout cg;

    }

    void sport :: get()

    {

    cout sport;

    cout year;

    }

    void student :: display()

    {

    cout

  • 8/13/2019 1 (1)jjk

    30/34

    int main()

    {

    student s;

    s.getdata();

    s.get();

    s.display();

    return 0;

    }

    19. Program to calculate the marks secured by a student.A Parent class with student identification is

    created and another class called marks is inherited from the main class.This class marks is further

    inherited by another class called sports and finally the sports class is inherited by the percentage

    class to calculated the percentage of marks.

    #include

    #include

    #include

    #include

    class student_id

    {

    int rno;

    char name[20];

    public:

    void read_id()

  • 8/13/2019 1 (1)jjk

    31/34

    {

    cout

  • 8/13/2019 1 (1)jjk

    32/34

    {

    display_nr();

    cout

  • 8/13/2019 1 (1)jjk

    33/34

    {

    total+=mark[i];

    }

    total+=sm;

    prcntge=(total/310)*100;

    }

    void display_totp()

    {

    display_m();

    cout

  • 8/13/2019 1 (1)jjk

    34/34

    }