OOP_C++_Practrice Questions-1

download OOP_C++_Practrice Questions-1

of 8

Transcript of OOP_C++_Practrice Questions-1

  • 8/18/2019 OOP_C++_Practrice Questions-1

    1/8

     

    Air University, Islamabad

    Department of Computer Science

    Name: Zain Zahid

    ID: 15000

    Section : !SCS"II"A

    OOP LAB 1

    Exercise 1

    #rite a pro$ram in C%% &hich carries out follo&in$ tas's

    " Create t&o inte$er variables (A and !) and assi$n values to them

    " *rint values of both variables on screen

    " *rint address of both variables

    " Create an inte$er pointer and point it to +rst inte$er variable (A)

    " *rint +rst variable (A) value usin$ pointer

    " *ointDirect pointer variable to second variable

    " *rint the value &here pointer points to

    " *rint address and value of pointer

    " *ro$ram should not e-it unless user decides to

    " Create second pointer and point pointer1 and pointer . to +rst variable

    " Create Chan$e value of value of +rst pointer and print value, chan$e value usin$

    second pointer and print value of variable

    #include using namespace std;

    int  main() {

    int a,b;

    a=10;

    b=11;

      cout

  • 8/18/2019 OOP_C++_Practrice Questions-1

    2/8

    /ab Instructor Adil Shahad

    Air University, Islamabad

    Department of Computer Science

    int !tr;

    !tr=&a;

    cout  int !tr%;

      !tr=!tr%=&a;

      !tr=1%;

      cout

  • 8/18/2019 OOP_C++_Practrice Questions-1

    3/8

    /ab Instructor Adil Shahad

    Air University, Islamabad

    Department of Computer Science

    Exercise 3

    #rite C%% pro$ram &hich reads a number from user and ma'es use of user de+ned

    function &hich accepts an inte$er pointer2 3his function should increment or decrement

    sent value by one dependin$ on user choice2 User should pass value by reference to the

    function and the option as an ar$ument (1 to increment and . to decrement value)2

    *ro$ram should repeat itself &ithout user choice2

    Custom function si$nature is4oid IncrementDecrement ( int number, int operation )6

    #include 

    using namespace std;

    void  IncrementDecrement(int number,int c)

    {

    if(c==1)

    {

    number=number+1;

    '

    if(c==%)

    {

      number=number1;

    '

    '

    int  main() {

    int n,c,coice;

    cout n;

    coutc;

    if(c==1)

    {

    coice=1;

    '

    if(c==%){

    coice=%;

    '

    -ncrement.ecrement(&n,coice);

    cout

  • 8/18/2019 OOP_C++_Practrice Questions-1

    4/8

    /ab Instructor Adil Shahad

    Air University, Islamabad

    Department of Computer Science

    #rite C%% pro$ram &hich reads a number from user and ma'es use of user de+ned

    function to calculate factorial2 *lease pass ar$ument by reference (usin$ pointer) and

    display result (factorial) in main function2

    #include 

    using namespace std;

    int actorial=1;

    void  fact(int number)

    {

    for(int i=1;i

  • 8/18/2019 OOP_C++_Practrice Questions-1

    5/8

    /ab Instructor Adil Shahad

    Air University, Islamabad

    Department of Computer Science

    '

    55#or $o*in7 8ars o ac $ub9ect

    for(int i=0;i

  • 8/18/2019 OOP_C++_Practrice Questions-1

    6/8

    /ab Instructor Adil Shahad

    Air University, Islamabad

    Department of Computer Science

    cout

  • 8/18/2019 OOP_C++_Practrice Questions-1

    7/8

    /ab Instructor Adil Shahad

    Air University, Islamabad

    Department of Computer Science

    '

    '

    if(oC=0)

    {

    cout

  • 8/18/2019 OOP_C++_Practrice Questions-1

    8/8

    /ab Instructor Adil Shahad

    Air University, Islamabad

    Department of Computer Science