Home
About Us
Contact Us
Bookmark
Saved Bookmarks
Current Affairs
General Knowledge
Chemical Engineering
UPSEE
BSNL
ISRO
BITSAT
Amazon
ORACLE
Verbal Ability
→
CLASSES
→
C# IN CLASSES
→
What are the differences between a data type struc...
1.
What are the differences between a data type struct and data type class in C++?
Answer»
struct
class
In C
++
struct all members are public by default.
Whereas in class all members are private by default.
structures are declared using the keyword struct
classes are declared using the keyword class
Example:
struct S1
{
int num; //default access //specifier is public
void setNum(int n)
{
//code
}
};
Example:
class C1
{
int num; //default access //specifier is private
public:
void setNum(int n)
{
//code
}
};
Show Answer
Discussion
No Comment Found
Post Comment
Related InterviewSolutions
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_nointegername20 charactersclass8 charactersmarks[5]integerpercentagefloatCalculate() 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 workerwname25 charactershrwrkfloat (hors worked and wagerate per hourtotwagefloat(hrwrk*wgrate)calcwgA fuction to find hrerk* wgrate with float return typePublic members of class workerin_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 nameDataTypeSizeNamefirstarray of characters60midarray of characters40lastarray of characters60phoneareaarray of characters4excharray of characters4numbarray of characters6class nameDateTypep-recnameNamephonePhonewith 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.
Reply to Comment
×
Name
*
Email
*
Comment
*
Submit Reply
Your experience on this site will be improved by allowing cookies. Read
Cookie Policy
Reject
Allow cookies