Question

In: Computer Science

A bag of cookies holds 40 cookies and these 40 cookies represent 10 servings, then how...

  1. A bag of cookies holds 40 cookies and these 40 cookies represent 10 servings, then how many cookies can you eat in 1 serving?

  1. List 4 principles of OOP and discuss why they are important to OOP.

Solutions

Expert Solution

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!!!


Related Solutions

A bag of cookies contains 40 cookies. The calorie information printed on the bag claims that...
A bag of cookies contains 40 cookies. The calorie information printed on the bag claims that there are 8 servings in each bag and that a single serving equals 300 calories. Design and write a C++ program that prompts your user for the number of cookies that he or she ate and then displays the calories they consumed. Use variables to represent the given information, such as the number of cookies in each bag and the number of calories in...
The number of chocolate chips in a bag of chocolate chip cookies is approximately normally distributed...
The number of chocolate chips in a bag of chocolate chip cookies is approximately normally distributed with mean 1263 and a standard deviation of 118. ​(a) Determine the 29th percentile for the number of chocolate chips in a bag. ​(b) Determine the number of chocolate chips in a bag that make up the middle 97% of bags. ​(c) What is the interquartile range of the number of chocolate chips in a bag of chocolate chip​ cookies?
The number of chocolate chips in a bag of chocolate chip cookies is approximately normally distributed...
The number of chocolate chips in a bag of chocolate chip cookies is approximately normally distributed with mean 1261 and a standard deviation of 118. ​(a) Determine the 28th percentile for the number of chocolate chips in a bag. ​(b) Determine the number of chocolate chips in a bag that make up the middle 96​% of bags. ​(c) What is the interquartile range of the number of chocolate chips in a bag of chocolate chip​ cookies?
The number of raisins in a 16-ounce bag of oatmeal raisin cookies is normally distributed with...
The number of raisins in a 16-ounce bag of oatmeal raisin cookies is normally distributed with a mean of 1021 raisins and a standard deviation of 2101 raisins. a. What proportion of 16-ounce bags of oatmeal raisin cookies contain fewer than 900 raisins? b. What is the probability that 14 random selected bags of oatmeal raisin cookies contain on average fewer than 900 raisins? c. Which is more likely: choosing a bag with fewer than 900 raisins, or choosing 14...
The number of chocolate chips in a bag of chocolate chip cookies is approximately normally distributed...
The number of chocolate chips in a bag of chocolate chip cookies is approximately normally distributed with mean 1261 and a standard deviation of 118. ​(a) Determine the 29th percentile for the number of chocolate chips in a bag. ​(b) Determine the number of chocolate chips in a bag that make up the middle 98​% of bags. ​(c) What is the interquartile range of the number of chocolate chips in a bag of chocolate chip​ cookies?
2. The number of chocolate chips in a bag of chocolate chip cookies is approximately normally...
2. The number of chocolate chips in a bag of chocolate chip cookies is approximately normally distributed with a mean of 1262 chips and a standard deviation of 118 chips Part (a): About how many percent of the cookie bags are in between 1200 and 1300 chips. Part (b): Determine the 30th percentile for the number of chocolate chips in a bag. Part (c): Determine the minimum number of chocolate chips in a bag that make up the middle 95...
The number of chocolate chips in a bag of chocolate chip cookies is approximately normally distributed...
The number of chocolate chips in a bag of chocolate chip cookies is approximately normally distributed with mean 1263 and a standard deviation of 118. ​(a) Determine the 2929th percentile for the number of chocolate chips in a bag. ​(b) Determine the number of chocolate chips in a bag that make up the middle 97​% of bags. ​(c) What is the interquartile range of the number of chocolate chips in a bag of chocolate chip​ cookies?
The number of chocolate chips in a bag of chocolate chip cookies is approximately normally distributed...
The number of chocolate chips in a bag of chocolate chip cookies is approximately normally distributed with mean of 1261 and a standard deviation of 117 ​(a) Determine the 26th percentile for the number of chocolate chips in a bag. ​(b) Determine the number of chocolate chips in a bag that make up the middle 96% ​(c) What is the interquartile range of the number of chocolate chips in a bag of chocolate chip​ cookies?
3, The number of chocolate chips in a bag of chocolate chip cookies is approximately normally...
3, The number of chocolate chips in a bag of chocolate chip cookies is approximately normally distributed with a mean of 1263 chips and a standard deviation of 118 chips. ​ ​(a) The 27th percentile for the number of chocolate chips in a bag of chocolate chip cookies is_____ chocolate chips. ​(Round to the nearest whole number as​ needed.) ​(b) The number of chocolate chips in a bag that make up the middle 95​% of bags is ___ to ___...
The number of chocolate chips in a bag of chocolate chip cookies is approximately normally distributed...
The number of chocolate chips in a bag of chocolate chip cookies is approximately normally distributed with a mean of 1261 chips and a standard deviation of 118 chips. ​(a) Determine the 27th percentile for the number of chocolate chips in a bag. ​(b) Determine the number of chocolate chips in a bag that make up the middle 97​% of bags. ​(c) What is the interquartile range of the number of chocolate chips in a bag of chocolate chip​ cookies?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT