STARTING OUT WITH C++ MPL
9th Edition
ISBN: 9780136673989
Author: GADDIS
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 11, Problem 11PC
Program Plan Intro
Prime Number Generation
Program Plan:
- Include the required header files
- Define the “Is_Composite” class.
- In public, define the function object for finding the given integer is composite value.
- Check if the number is composite.
- Check for the existence of factors up to the square root of the number.
- Return true.
- Check for the existence of factors up to the square root of the number.
- Otherwise, return false.
- Check if the number is composite.
- In public, define the function object for finding the given integer is composite value.
- Define the “main ()” function.
- Create a
vector object. - Get an input from the user.
- Push all the values into the vector.
- Remove all the composites from the vector.
- Display an output.
- Create a
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
1 def all_fluffy(s: str) -> bool:
2
"""Return True iff every letter in s is fluffy. Fluffy letters are those
3.
that appear in the word 'fluffy'.
4
#TODO: Add at least one example to the docstring and complete the body
7
8
9
10
#TODO: Now complete the function body
Describe scenarios where passing function objects as arguments can be beneficial.
A destructor function is called automatically when the object goes out of scope:
I. the function ends
II. the program ends
III. a block containing local variables ends
Chapter 11 Solutions
STARTING OUT WITH C++ MPL
Ch. 11.3 - What is the difference between an instance member...Ch. 11.3 - Static member variables are declared inside the...Ch. 11.3 - Does a static member variable come into existence...Ch. 11.3 - What limitation does a static member function...Ch. 11.3 - What action is possible with a static member...Ch. 11.3 - If class X declares function f as a friend, does...Ch. 11.3 - Suppose that class Y is a friend of class X,...Ch. 11.5 - Briefly describe what is meant by memberwise...Ch. 11.5 - Prob. 11.9CPCh. 11.5 - Prob. 11.10CP
Ch. 11.5 - When is a copy constructor called?Ch. 11.5 - How does the compiler know that a member function...Ch. 11.5 - What action is performed by a classs default copy...Ch. 11.6 - Assume there is a class named Pet. Write the...Ch. 11.6 - Assume that dog and cat are instances of the Pet...Ch. 11.6 - What is the disadvantage of an overloaded ...Ch. 11.6 - Prob. 11.17CPCh. 11.6 - Prob. 11.18CPCh. 11.6 - Assume there is a class named Animal, which...Ch. 11.6 - Prob. 11.20CPCh. 11.6 - Describe the values that should he returned from...Ch. 11.6 - Prob. 11.22CPCh. 11.6 - What type of object should an overloaded operator...Ch. 11.6 - Prob. 11.24CPCh. 11.6 - If an overloaded or operator accesses a private...Ch. 11.6 - Prob. 11.26CPCh. 11.6 - When overloading a binary operator such as or as...Ch. 11.6 - Explain why overloaded prefix and postfix and ...Ch. 11.6 - Prob. 11.29CPCh. 11.6 - Overload the function call operator ( ) (int i,...Ch. 11.8 - Prob. 11.31CPCh. 11.8 - How is the type declaration of an r value...Ch. 11.8 - Prob. 11.33CPCh. 11.8 - Prob. 11.34CPCh. 11.8 - Which operator must be overloaded in a class...Ch. 11.8 - Prob. 11.36CPCh. 11.10 - What arc the benefits of having operator functions...Ch. 11.10 - Prob. 11.38CPCh. 11.10 - Assume that there is a class named BlackBox. Write...Ch. 11.10 - Assume there are two classes, Big and Smal1.Write...Ch. 11.13 - What type of relationship between classes is...Ch. 11.13 - Why does it make sense to think of a base class as...Ch. 11.13 - What is a base class access specification?Ch. 11.13 - Think of an example of two classes where one class...Ch. 11.13 - What is the difference between private members and...Ch. 11.13 - What is the difference between member access...Ch. 11.13 - Suppose a program has the following class...Ch. 11.14 - What is the reason that base class constructors...Ch. 11.14 - Why do you think the arguments to a base class...Ch. 11.14 - Passing arguments to base classes constructors...Ch. 11.14 - What will the following program display? #include...Ch. 11.14 - What will the following program display? #include...Ch. 11 - If a member variable is declared _____, all...Ch. 11 - Static member variables are defined _____ the...Ch. 11 - A(n) _____ member function cannot access any...Ch. 11 - A static member function may be called _____ any...Ch. 11 - A(n) _____ function is not a member of a class,...Ch. 11 - A(n) _____ tells the compiler that a specific...Ch. 11 - _____ is the default behavior when an object is...Ch. 11 - A(n) _____ is a special constructor, called...Ch. 11 - _____ is a special built-in pointer that is...Ch. 11 - An operator may be _____ to work with a specific...Ch. 11 - When the _____ operator is overloaded, its...Ch. 11 - Making an instance of one class a member of...Ch. 11 - Object composition is useful for creating a(n)...Ch. 11 - A constructor that takes a single parameter of a...Ch. 11 - The class Stuff has both a copy constructor and an...Ch. 11 - Explain the programming steps necessary to make a...Ch. 11 - Explain the programming steps necessary to make a...Ch. 11 - Consider the following class declaration: class...Ch. 11 - Describe the difference between making a class a...Ch. 11 - What is the purpose of a forward declaration of a...Ch. 11 - Explain why memberwise assignment can cause...Ch. 11 - Explain why a classs copy constructor is called...Ch. 11 - Explain why the parameter of a copy constructor...Ch. 11 - Assume a class named Bird exists. Write the header...Ch. 11 - Assume a class named Dollars exists. Write the...Ch. 11 - Assume a class named Yen exists. Write the header...Ch. 11 - Assume a class named Length exists. Write the...Ch. 11 - Assume a class named Collection exists. Write the...Ch. 11 - Explain why a programmer would want to overload...Ch. 11 - Each of the following class declarations has...Ch. 11 - A derived class inherits the _____ of its base...Ch. 11 - The base class named in the following line of code...Ch. 11 - The derived class named in the following line of...Ch. 11 - In the following line of code, the class access...Ch. 11 - In the following line of code, the class access...Ch. 11 - Protected members of a base class are like _____...Ch. 11 - Complete the following table by filling in...Ch. 11 - Complete the following table by filling in...Ch. 11 - Complete the following table by filling in...Ch. 11 - When both a base class and a derived class have...Ch. 11 - When both a base class and a derived class have...Ch. 11 - An overridden base class function may be called by...Ch. 11 - Each of the following class declarations and/or...Ch. 11 - Soft Skills 44. Your companys software is a market...Ch. 11 - Check Writing Design a class Numbers that can be...Ch. 11 - Day of the Year Assuming that a year has 365 days,...Ch. 11 - Day of the Year Modification Modify the DayOfYear...Ch. 11 - Number of Days Worked Design a class called...Ch. 11 - Palindrome Testing A palindrome is a string that...Ch. 11 - Prob. 6PCCh. 11 - Corporate Sales A corporation has six divisions,...Ch. 11 - Prob. 8PCCh. 11 - Rational Arithmetic II Modify the class Rational...Ch. 11 - HTML Table of Names and Scores Write a class whose...Ch. 11 - Prob. 11PC
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- A destructor function is called automatically when the object goes out of scope: I. the function ends II. the program ends III. a block containing local variables ends A. I , II, III B. I, II, C. Only II D. I , IIIarrow_forwardComputer Science Create a class that will store a list of names. Your class needs to include a function that will return the name that appears first aphabetically, and another function that should return the name that appears last alphabetically. You also need to include a function that will sort the list alphabetically. The class does not need to be case insensitive.arrow_forward13. What is the difference between a formal parameter and an argument? Group of answer choices A function’s argument is referred to as the formal argument to distinguish it from the value that is passed in during the function call. The parameter is the passed value. They are identical but using different terms. A function’s parameter is used for passing by reference. The argument is used for passing by value. A function’s parameter is referred to as the formal parameter to distinguish it from the value that is passed in during the function call. The argument is the passed value. A function’s parameter is used for passing by value. The argument is used for passing by reference.arrow_forward
- What does the function f do? struct Point2D { double x; double y; struct Triangle { Point2D v1; Point2D v2; Point2D v3; }; void f(Triangle&t) { } int temp = 12.5; temp = t.v1.x; t.v1.x = t.v1.y; t.v1.y = temp; } int main () { Triangle mytri; mytri.v1.x = 1.0; mytri.v1.y = 22.5; f (mytri); Swaps values of x and y in vertex 1 of an argument of type Triangle Initializes value of x in vertex 1 of an argument of type Triangle Sets all x,y values in all vertices of an argument of type Triangle Swaps value of x in vertex 1 with value of x in vertex 2, for an argument of typearrow_forwardc++ Friend function concepts Do not use operator overloading Create a class Circle with member variable radius R of type float. Create a constructor for assigning value to R and a method "int compare(Circle c)" for comparing the radii. In main method, create two objects of Circle and compare their radii and display which one is biggerarrow_forwardProgramming Skills: Complete the function egg_category which returns a str describing an egg's category given its int weight in grams. Here is a table specifying the weight ranges if an egg's weight is on the boundary between two category ranges, it is assigned the smaller category. Category Small Meduim Weight no more than 50 grams 50-57 grams Category Large Jumbo Weight 57-64 grams more than 64 grams def egg_category (weight): %# Return a str describing the category of an egg of the specified int weight.arrow_forward
- Language : C++ Subject : OOP Suppose we have a class Rectangle which has two data members, length and width. In addition, there should be a static variable, namely allRectanglesTotalArea which stores the area of all the Rectangles created. Furthermore, there should be a function named calcRectangleArea() which calculates the area of rectangle and adds it to the allRectanglesTotalArea. Write a static function nameddisplayAllRectanglesTotalArea()which displays the value of allRectanglesTotalArea. The main function of the program should look like the following. intmain() { Rectangle r1(5.0,4.0); r1.calcRectangleArea(); Rectangle r2(2.5,4.0); r2.calcRectangleArea(); Rectangle::displayAllRectanglesTotalArea(); return 0; }arrow_forwardResearch assistants provide support to professionals who are conducting experiments or gathering andanalyzing information and data. Suppose you are working as RA (research assistant) with a Professor who isworking on a project and evaluating complex mathematical equations. Your duty is to assist him, so in thisregard he has assigned a task to you. Your task is to write a oop c++ program to create a class named equation which will have the data members a, b and c which are the coefficients of the quadratic equation. The class will have two more data members namely proot and nroot which stand for the positive root and negative root of the equation. Suppose that variables a, b and c are integers. Where proot and nroot are floats. Input Function to get values of a, b and c Then design a friend function which will determine the proot and nroot of the equation. Create another friend function which will display the values of proot and nroot.arrow_forwardneed help defining a function, dogBreeder, that accepts up to two optional arguments: name (string) age (number) dogBreeder should return an object that represents a new dog! If the user doesn't define a name, assume the dog's name is 'Steve'. If the user doesn't define the dog's age, assume the dog's age is 0. example dogBreeder('Sam', 12) // => {name: 'Sam', age: 12} dogBreeder(15) // => {name:'Steve', age: 15} dogBreeder('Sam') // => {name:'Sam', age: 0} dogBreeder() // => {name: 'Steve', age: 0}arrow_forward
- C++arrow_forwardC++ Create a class Student that contains three members: roll no, name and mark, and three functions. Write a first inputStudent() function to get data of student class. Write a second getMark() function that returns a student’s mark. Write a third display() function that displays a student’s data. In a main() function, you need to declare 40 students and get data of all students by using inputStudent() function. And also use a pointer array to keep all students by mark greater than 50 and display the searching data of each student in that pointer array (Use the access operator -> to access a pointer points to member functions of the Student class).arrow_forwardcomputer programming (C++ language)arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr