In: Computer Science
Number of cookies you can eat in one serving is 4.
C++ code for the given question along with output screen is given below :
#include<bits/stdc++.h>
using namespace std;
int main()
{
//initialization of variables
long long bag,serve,one_serve=0;
//Asking from user to input
cout<<"enter the number of cookies a bag can hold: ";
cin>>bag;
//Asking from user to input
cout<<endl<<"enter the number of servings: ";
cin>>serve;
//applying formula for getting the value of one serving
one_serve = bag/serve;
//output of answer
cout<<endl<<"number of cookies you can eat in 1 serving is: "<<one_serve;
return 0;
}
Output screen:
FOUR Principles of OOP (Object Oriented Programming) are :
Encapsulation
Abstraction
Inheritance
Polymorphism
Importance of these four principles in OOP are:
Encapsulation: Encapsulation works as a protective barrier which seperates the certain peice of information from rest of the code . With the help of Encapsulation, a programmer can stop the objects from interacting with each other, they are supposed to be encapsulated in individual classes. Hence Encapsulation is an important part of Object oriented programming (OOP).
Abstraction: Abstraction makes the interfaces of objects simpler by hiding certain properties of working. It also helps programmer in isolating the impacts of changes made in a code, these changes will not affect the outside code. Hence Abstraction is an important part of Object oriented programming (OOP).
Inheritance: In this, the object acquies all the properties of it's parent object automatically. Inheritance increases the functionality of the code's existing classes which eliminates the repetitive code. When a class is created with the help of Inheritance, then the new class is called derived class and the class from which the derived class is created is known as Parent class. Hence Inheritance is an important part of Object oriented programming (OOP).
Polymorphism: Polymorphism in OOP is the ability of data which can be processed in more the one form. The use of polymorphism in object oriented programming comes into play when a parent class reference is used to refer to child class object. With the help of polymorphism, an object can play various roles at the same time. Hence Polymorphism is an important part of Object oriented programming (OOP).
Thank you!!!