C++ Answers

Questions answered by Experts: 9 913

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search

Write a method that receives elapsed time for an event in seconds as a parameter. The
method then displays the elapsed time in hours, minutes, and seconds. For example, if the
elapsed time is 9630 seconds, then the method will display is 2:40:30. Write a main()
method that will prompt a user for elapsed time for an event in seconds, and use received
value to demonstrate that the method works correctly. Save the file as ElapsedTime.cpp
3

Consider an array MARKS[20][5] which stores the marks obtained by 20 students in 5 subjects. Now write a program to

(a) find the average marks obtained in each subject.

(b) find the average marks obtained by every student.

(c) find the number of students who have scored below 50 in their average.

(d) display the scores obtained by every student.


WAP to create the classes as per the hierarchy shown below.Include the data members in the relevant classes to store the following information:-

Name, Id, No of matches played,No. of runs scored, No. of wickets taken.

Calculate the batting average and wickets per match for an all rounder player.Use parameterized constructor to initialize the object.

[ Batting average=No. of runs scored/No. of matches played

 Wickets per match= No. Of wickets taken/ No. of matches played ]

 



WAP to Create a class ‘Book’. Derive two classes from it namely ‘’Print_Book’ and ‘E_Book’. Store the following details about the book in the relevant classes. Title, Author, Price, No of pages and Size in KB. Input information for ‘m’ number of print books and ‘n’ number of eBooks and display it.


WAP to create a class which stores a dynamic integer array and its size. Include all the constructors and destructor in the class. Store two arrays of different size in two objects. Join the two arrays and and store it in another object using a member function.


Complete the given code to get the output shown below:-

Base1

Base2


#include<iostream>

using namespace std;

class Base1 {

 public:

     void display()

     { cout << " Base1"<< endl; }  };

class Base2 {

public:

    void display()

     { cout << "Base2"<<endl"; } };

class Derived: public Base1, public Base2 {

   public:

 };

int main()

{

   Derived d;

   return 0;



Write the parameterized constructor for all the classes in the hierarchy.


class A

{ int a;}

Class B:public virtual A

{int b;}

Class C:public virtual A

{int c; }

Class D:public b,public C

{int d;}


Consider the class hierarchy shown below.


class A

{  int a;

protected:

int b;

public:

int c;   };

class B: protected A

{  };

Class C: public B

{   };


Which data members of class A are accessible

- in class B       

-in class C       

-in main function 

Justify your answer.



Include the function calls at appropriate places in the given program, to get the output as shown below

In base

In derived


#include<iostream>

using namespace std;

class base

{ int b;

protected:

void display(){cout<<"In base\n";}

};

class derived:public base

{ int d;

  public:

void display(){ cout<<"In derived\n";}

};

int main()

{ derived D;

   return 0;

}



Consider the code given below.

[Assume all the header files and namespaces included.]

How many times the following are invoked:

I) Default constructor

II) Parameterized constructor

III)  Copy constructor

IV) Destructor


class test

{    int a;

public:

test(){a=0;}

test(int x) {a=x;}

test(const test &T){a=T.a;}

~test(){ }

test add(test X)

{ test T;

      T.a=a+X.a;

      return 0;

}

};

int main()

{  test t1(5),t2(10),t3;

   t3=t1.add(t2);

   return 0;

}



LATEST TUTORIALS
APPROVED BY CLIENTS