Can’t find an answer?

Can’t find an answer?

Ask us to get the answer

  • This forum has 0 topics, and was last updated 1 year ago by Anonymous.

Can we use the same function name for a member function of a class and an outside i.e., a non-member function in the same program file? If yes, how are they distinguished? If no, give reasons. Support your answer with examples.

Consider the following class declaration and answer the questions below:

class SmallObj

{

private:

int some,more;

void err_1() {cout<<“error”;}

 public:

void Xdata(int d) {some=d;more=d++; }

void Ydata() {cout<<some<<” “<<more; }

};

(i) Write the name that specifies the above class.

(ii) Write the data of the class with their access scope. 

(iii) Write all member functions of the class along with their access scope.

(iv) Indicate the member function of the SmallObj that sets data.

Define a class Student with the following specification: private members:

roll_nointeger
name20 characters
class8 characters
marks[5]integer
percentagefloat

Calculate() function that calculates overall percentage of marks and returns the percentage of marks.

public members:

Readmarks() a function that reads marks and invokes the calculate functio Displaymarks() a function that prints the marks.

What are static members of a class? When and how are they useful?

Write a program that invokes a function newdate() to return a object of date type. The function newdate() takes two parameters: an object olddate of date type and number of days (int) to calculate the newdate as olddate + number of days and returns the newdate.

Define a class to represent batsmen in a cricket team. Include the following members: Data Members: First name, Last name, Runs made, Number of fours, Number of sixes Member Functions:

(i) To assign the initial values

(ii) To update runs made (It should simultaneously update fours and sixes, if required). 

(iii) To display the batsman’s information Make appropriate assumptions about access labels.

Define a class worker with the following specification: Private members of class worker

wname25 characters
hrwrkfloat (hors worked and wagerate per hour
totwagefloat(hrwrk*wgrate)
calcwgA fuction to find hrerk* wgrate with float return type

Public members of class worker

in_data() a function to accept values for wno, wname, hrwrk, wgrate and invoke calcwg() to calculate totwage.
out_data() a function to display all the data members on the screen you should give definations of functions

What are the differences between a data type struct and data type class in C++?

Considering the following specifications:

Structure nameDataTypeSize
Namefirstarray of characters60
midarray of characters40
lastarray of characters60
phoneareaarray of characters4
excharray of characters4
numbarray of characters6

class nameDateType
p-recnameName
phonePhone

with member functions constructors and display_rec.

(i) Declare structures in C++ for Name and Phone.

(ii) Declare a class for P_rec.

(iii) Define the constructor (outside the class P_rec) that gathers information from the user for the above two structures Name and Phone.

(iv) Define the display_rec (outside the class P_rec) that shows the current values.

Define a class to represent bowlers in a cricket team. Include the following members: Data Members: First name, Last name, Overs bowled, Number of Maiden overs, Runs given, Wickets taken. Member Functions:

(i) To assign the initial values,

(ii) To update the information,

(iii) To display the bowler’s information Make appropriate assumptions about access specifiers.

Viewing 15 topics - 1 through 15 (of 54 total)

1 2 3 4
  • You must be logged in to create new topics.