C++ HOLIDAY HOMEWORK ASSIGNMENT WITH MARKING ... C++ HOLIDAY HOMEWORK ASSIGNMENT WITH MARKING SCHEME

  • View
    1

  • Download
    0

Embed Size (px)

Text of C++ HOLIDAY HOMEWORK ASSIGNMENT WITH MARKING ... C++ HOLIDAY HOMEWORK ASSIGNMENT WITH MARKING SCHEME

  • C++ HOLIDAY HOMEWORK ASSIGNMENT WITH MARKING SCHEME

    CHAPTER -1 C++ REVISION

    1.(a)What is the difference between Global Variable and Local Variable? Also, give a

    suitable C++ code to illustrate both. 2

    (b) Which C++ header file(s) will be essentially required to be included to run /execute

    the following C++ code: 1

    void main()

    {

    char Msg[ ]="Sunset Gardens";

    for (int I=5;I>Mno>>Fees;}

    void Display{cout

  • GAME G={110,50};

    Play(G,10);

    cout

  • cout

  • for (int L=0;L

  • Q 3.)(i)Write the names of the header files to which the following belong :

    (1/2) MARK EACH

    puts(), sin(), setw(), sqrt(), strcat(), gets(), strcpy(), abs(), isupper(), pow(), random(),

    strcmp(), isalnum(), isalpha(), fabs()

    (ii) In the following program, find the correct possible output(s) from the options: (2)

    #include

    #include

    void main ( )

    {

    randomize( );

    char Area[][10]= {“NORTH”, “SOUTH”, “EAST”, “WEST”};

    int ToGo;

    for(int I = 0; I

  • cin>>N;

    Guessme=random(N)+10;

    cout

  • int a[SIZE]={10,20,30,40,50};

    float x=2;

    SIZE=5;

    for(int i=0;i

  • help of random function , if the number generated by the random number is

    supposed to be between the range of 20-2000 2

    #include

    #include

    randomize();

    r=___________________//statement 1

    cout

  • void main()

    {

    char str[]="SUCCESS";

    cout

  • CHAPTER – OBJECT ORIENTED PROGRAMMING

    1.(a) What do you understand by Data Encapsulation and Data Hiding? Also, give a suitable

    C++ code to illustrate both. 2

    (b) Answer the questions (i) and (ii) after going through the following class: 2

    class Seminar

    {

    int Time;

    public:

    Seminar() //Function 1

    {

    Time=30;cout

  • (NoCandidates/100+1)

    Public Members

    • A function SCHEDULE() to allow user to enter values for TestCode,

    Description, NoCandidate & call function CALCNTR() to calculate the number of

    Centres

    • A function DISPTEST() to allow user to view the content of all the data members

    (d) Answer the questions (i) to (iv) based on the following: 4

    class PUBLISHER

    {

    char Pub[12];

    double Turnover;

    protected:

    void Register();

    public:

    PUBLISHER();

    void Enter();

    void Display();

    };

    class BRANCH

    {

    char CITY[20];

    protected:

    float Employees;

    public:

    BRANCH();

    void Haveit();

    void Giveit();

    };

    class AUTHOR : private BRANCH , public PUBLISHER

    {

    int Acode;

    char Aname[20];

    float Amount;

    public:

    AUTHOR();

    void Start();

    void Show();

    };

    (i) Write the names of data members, which are accessible from objects belonging to class

    AUTHOR.

  • (ii) Write the names of all the member functions which are accessible from objects

    belonging to class BRANCH.

    (iii) Write the names of all the members which are accessible from member functions of

    class AUTHOR.

    (iv) How many bytes will be required by an object belonging to class AUTHOR?

    Q2. (a) What do you understand by Polymorphism? Give a suitable example of the

    same. 2

    (b) Answer the questions (i) and (ii) after going through the following program: 2

    class Match

    {

    int Time;

    public:

    Match()

    //Function 1

    {

    Time=0;

    cout

  • • A data member Distance of type float

    • A data member Fuel of type float

    • A member function CALFUEL() to calculate the value of Fuel as per the

    following criteria

    Distance Fuel

  • void Sales_Detail();

    };

    (i) Write the names of data members which are accessible from objects belonging to

    class CUSTOMER.

    (ii) Write the names of all the member functions which are accessible from objects

    belonging to class SALESMAN.

    (iii) Write the names of all the members which are accessible from member functions of

    class SHOP.

    (iv) How many bytes will be required by an object belonging to class SHOP?

    Q3.) Answer the questions (i) to (iv) based on the following code:

    class Cricketer

    char category[20];

    protected:

    float match_fee;

    void calc_match_fee(float);

    public:

    Cricketer();

    void CInput();

    void CShow();

    };

    class Bowler : public Cricketer

    char BOWLERName[20];

    int Wickets;

    public:

    Bowler();

    void BOWInput();

    void BOWShow();

    };

    class Batsman : public Cricketer

    char BASTSMANName[20];

    int Centuries;

    float Bat_Average;

    public:

    Batsman();

    void BATInput();

    void BATShow();

    };

    (i) Which type of Inheritance is shown in the above example?

    (ii) How many bytes will be required by an object of the class Batsman?

    (iii) Write name of all the data members accessible from member functions of the class

  • Bowler?

    (iv) Write the name of all the member functions accessible by an object of the class

    Batsman?

    Q4. (a) Differentiate between a default and a parameterized constructor in context of class

    and object . Give suitable example in C++. 2

    (b) Answer the questions (i) and (ii) after going through the following class : 2

    class Computer

    {

    char C_name[20];

    char Config[100];

    public:

    Computer(Computer &obj); // function1

    ~Computer(); //function 2

    };

    (i) Write the statement(s) which will invoke the function 1.

    (ii) Name the specific feature of the class shown by function 2. Also

    write the time of its invoke.

    (c) Define a class Shop in C++ with the description given below : 4

    private members

    name array of 40 characters

    address array of 40 characters

    type of item array of 3X20 characters

    availqty array of 3 integers

    totalqty array of 3 integers

    public members

    init() function to ask and store the values of address ,type

    of item from the user and updates the totalqty and avialqty

    accordingly .

    display() function to display the details of the item in the

    following format :

    Name :

    Address :

    Items :

  • Balance Stock :

    (d) Answer the questions (i) to (iv) based on the following code : 4

    class Goods

    {

    int id;

    protected :

    char name[20];

    long qty;

    void Incr(int n);

    public :

    Goods();

    ~Goods();

    void get();

    };

    class Food_products : protected Goods

    {

    char exp_dt[10];

    protected :

    int id;

    int qty;

    public :

    void getd();

    void showd();

    };

    class Cosmetics : private Goods

    {

    int qty;

    char exp_date[10];

    protected :

    int id;

    public :

    ~Cosmetics();

    Cosmetics();

    void show();

    };

    (i) Name the all protected members of class Food_products.

    (ii) Name the member functions accessible through the object of class

    Food_products.

    (iii) From the following, Identify the member function(s) that cannot be called

    directly from the object of class Cosmetics

  • show()

    getd()

    get()

    (iv) If the class cosmetics inherits the properties of food_products class also,

    then name the type of inheritance.

    Q5.) Differentiate between data abstraction and data hiding. 2

    b. Answer the questions (i) and (ii) after going through the following class : 2

    class Exam

    {

    int Rollno;

    char Cname[25];

    float Marks ;

    public :

    Exam( ) //Function 1

    {

    Rollno = 0 ;

    Cname=””;

    Marks=0.0;

    }

    Exam(int Rno, char candname) //Function 2

    {

    Rollno = Rno ;

    strcpy(Cname,candname);

    }

    ~Exam( ) //Function 3

    {

    cout

  • A data member Cname of type string

    A data members Agg_marks (Aggregate Marks) of type float

    A data members Grade of type char

    A member function setGrade () to find the grade as per the aggregate marks

    obtained by the student. Equivalent aggregate marks range and the respective grade as

    shown

    below.

    Aggregate Marks Grade

    >=80 A

    Less than 80 and >=65 B

    Less than 65 and >=50 C

    Less than 50 D

    Public members:

    A constructor to assign default values to data members:

    Rno=0,Cname=”N.A”,Agg_marks=0.0

    A function Getdata () to allow users to enter values for Rno. Cname, Agg_marks and call