A.With the advent of object-oriented programming, is it ever necessary to use C-
ID: 3540490 • Letter: A
Question
A.With the advent of object-oriented programming, is it ever necessary to use C-type
structs rather than classes? If so, when? What are the advantages or disadvantages
of each approach? (5 points) (Think about how the object-oriented concept of
reusability relates to structs, structs within arrays, arrays within structs, and structs within
structs. Think of some applications in which defining these data types for later use
would be beneficial) (3 points) total(8 points)
B. Discuss the relevant issues when determining whether to use public, protected or
private members when defining new classes, especially base classes. (5 points)Are
there any risks involved with using the protected member access specifier instead of the
private member access specifier?. 3 points) (8 points Total)
Explanation / Answer
A)
no,it is not necessary to use structs rather than class.
difference
1)
structure is a collection of data while class is a collection of datta and function .
2)
All member are public in a structure whereas all member are private by default in class
reusability:
struct stutype
{
short rollno;
char name[21];
short class;
float marks;
char grade;
} senior_stu,junior_stu
this template is used to store the both junior and senior student details everytime we want;
B)
public members can be used by any function
private members are hidden from outside world.this impliment the OOP concept of data hiding.it only be used by member function of class in which it is declared.
protected member can be used only by member function and friends of the class in which it is declared.it is similer to private members that they canot be accessed by non member function. the difference between protected and private becomes clear by inheritance because protected members are inheritable but private not;this can be say that it is a risk;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.