Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Programming assignment, answer the following questions 1.What is Object Orie

ID: 3845298 • Letter: C

Question

C++ Programming assignment, answer the following questions

1.What is Object Oriented Programming (OOP?
2.What structs are and what they are used for? How to create one and use it. How to assign values to fields and access them. How to use the assignment operator to assign a struct object to another one?
3.What classes are? How to Write a class and use a class as a client to create objects and have them do things.

4.What are constructors, data members (fields) and member functions?

5. Explain the 4 pillars of OOP:
          - Classes
          - Encapsulation
          - Inheritance
         - Polymorphism

Explanation / Answer

1. OOP is language model centred around objects rather than procedures( that is functions). OOP treats data as critical element in program development. It ties data more closely to methods that operate on it and protects it from accidental modification from outside functions. OOP allows dividing problem into number of small objects and methods around these objects to make large problem easier to solve. The data of one object can be accessed by methods from same object but methods of one object can be accessed by other object.

2. structs are groups of data of different types. for example if one wants to store information about employee such as name, age , salary etc. you can store it in single variable as given below

struct employee{

    char Name[100];

   int Age;

   double Salary;

};

to use it we need to define variable of type struct

employee Nick;

to assign values to fields, use the dot(.) operator

Nick.Name = "Nick Doe";

Nick.Age = 33;

Nick.Salary = $500;

to access fields also use dot(.) operator

int Age = Nick.Age;

double sal = Nick.Salary;

lets say you have to objects NIck and John of type employee if you use assignment operator to assign one object to other the default copy constructor will be envoked and all data fields will be copied from one object ot other

employee John;

John = Nick;

so John.Name will be "Nick" and so on.

3.Classess are blue print for objects. it combines data and methods on those data as single entity. classes can be defined with class keyword

class employee{

   char Nama[100];

   double salary;

   public:

   double getSalary(){ return salary;}

   char * getName(){return Name;}

void setSalary(double x){salary = x; }

void setName(char* n){Name =n;}

};

int main(){

employee john,nick;

char name1[] ="John";

char name2[]= "Nick";

john.setName(name1);

john.setSalary(5500.0);

nick.setName(name2);

nick.setSalary(1500.0);

cout << "Employee name   " <<"Salay" << endl;

cout << john.getName() << " " << john.getSalary() << endl;

cout <<nick.getNama() << " " << nick.getSalary() << endl;

}

4.Ans

Constructors are functions of class with no return value they are invoked when object is being created for first time, object is being assigned to another object. their purpose is to initialize data members of objects.

data members are fields inside classes they are initialized by constructors if defined one other wise the are default to some value, the can be accessed by member functions of class and can be modified by them. the can be made public or private or protected(for use in other inherited class).

5.

classes - Classes are blue print for objects it defines data members and methods associated with them

Encapsulation- also known as data hiding, it defines data as private members of objects and can be accessed only through methods associated with objects.

inheritance - It is reuse of code without writing new same code. classes can be inherited by other classess. the class which inherit other class is child class and the class from which it inherits is called parent class. all public and protected members of inherited class are accessible to child class. the parent class's member variables needs to be initialized before using child class.

Polymorphism- means one of may forms. suppose parent class defines abstract method which two child classes inherits and defines them according to their own needs. suppose we define pointer to parent class and used the same pointer to point to child class. then the method(which is inherited abstract) which is called depends on who it points to. so calling same method on different child will have different effect. this is called polymorphism

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote