Concept explainers
Sequence Sum
A sequence of integers such as 1, 3, 5, 7,... can be represented by a function that takes a non-negative integer as parameter and returns the corresponding term of the sequence. For example, the sequence of odd numbers just cited can be represented by the function
int odd(int k) {return 2 * k + 1;}
Write an abstract class AbstractSeq that has a pure virtual member function
virtual int fun(int k) = 0;
as a stand-in for an actual sequence, and two member functions
void printSeq(int k, int m);
int sumSeq(int k, int m)
that are passed two integer parameters k and m, where k < m. The function printSeq will print all the terms fun(k) through fun(m) of the sequence, and likewise, the function sumSeq will return the sum of those terms. Demonstrate your AbstractSeq class by creating subclasses that you use to sum the terms of at least two different sequences. Determine what kind of output best shows off the operation of these classes, and write a
Want to see the full answer?
Check out a sample textbook solutionChapter 15 Solutions
Starting Out With C++: Early Objects (10th Edition)
Additional Engineering Textbook Solutions
Database Concepts (8th Edition)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Absolute Java (6th Edition)
Starting Out with Java: Early Objects (6th Edition)
Starting out with Visual C# (4th Edition)
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
- Given the definition of a class called Bag as following: class Bag { private: public: int items[100]; int itemCount; Bag(); bool add(int item); bool contains(int item); }; Please provide the implementation of the member function: contains(int item) - This function returns true if the item is one of the integers stored in the bag, otherwise, return false.arrow_forwardActivity - Abstract Class An English teacher wants to find assessment mark of all the students in his course. Write a java program to find assessment mark of the students using following instructions. Save the project/file as StudentAbstract. A) Abstract Class name: Assessment Abstract Member Method: - to calculate and return total score totalScore() B) Class name: English extends Assessment Member variables: QuizMark, PracticeTest, ListeningMark Member Method : - Constructor to initialize member variables - to calculate and return total score totalScore QuizMark + PracticeTest*0.25 + %3D ListeningMark/2 C) Controlling class : StudentAbstract - To create an object of English class - To print totalScore of the Englisharrow_forwardCONSTRUCTOR// IntSet()// Pre: (none)// Post: The invoking IntSet is initialized to an empty// IntSet (i.e., one containing no relevant elements).// CONSTANT MEMBER FUNCTIONS (ACCESSORS)// int size() const// Pre: (none)// Post: Number of elements in the invoking IntSet is returned.// bool isEmpty() const// Pre: (none)// Post: True is returned if the invoking IntSet has no relevant// relevant elements, otherwise false is returned.// bool contains(int anInt) const// Pre: (none)// Post: true is returned if the invoking IntSet has anInt as an// element, otherwise false is returned.// bool isSubsetOf(const IntSet& otherIntSet) const// Pre: (none)// Post: True is returned if all elements of the invoking IntSet// are also elements of otherIntSet, otherwise false is// returned.// By definition, true is returned if the invoking IntSet// is empty (i.e., an empty IntSet…arrow_forward
- Implement a class named Animal has two private member variables: name of type string and numLegs of type int, and has the following member functions: • setName—Function to set the name • setNumLegs—Function to set the number of animal legs • getName—Value-returning function to return the name • getNumLegs—Value-returning function to return the number of animal legs • speak()—Value-returning function to return the empty string • move()—Value-returning function to return the empty string • print()—Outputs the data stored in the instance variables with the appropriate titles • Constructor with parameter—Sets the values of the instance variables to the values specified by the user, in default: sets name to the empty string and number of legs to 0 2. Using an Animal class as a base class, implement two derived classes simulating a Cat and Dog, each redefining three functions constructor, speak(), move() to represent each animal the most suitable. 3. Write a function to handle the…arrow_forwardDefine access private member of a classarrow_forwardAll virtual functions in an abstract base class must be declared as pure virtual functions T/Farrow_forward
- One use of the this pointer is to access a data member when there is a local variable with the same name. For example, if a member function has a local variable x and a data member x, then you can refer to the data member as this->x. Use this fact to complete the constructor implementation of this Point class: class Point { public: Point(int x, int y); int get_x() const; int get_y() const; private: int x; int y; }; Not all lines are useful.arrow_forwardc++ please The Critter class is a base class with some basic functionality for running simulations of different kinds of critters. Critters can move, act, and remember their history. A typical simulation contains a number of critters of different types. In each step of the simulation, the act member function will be called on each critter. Define a class Sloth derived from Critter that simulates a sloth. Sloths alternate between eating and sleeping. Add the word "eat" or "sleep" to the history each time the act function is called. The implementation of the Critter class is not shown. Complete the following file: sloth_Tester.cpp #include <iostream>using namespace std; #include "critter.h" /**A sloth eats and sleeps.*/class Sloth : public Critter{public:Sloth();. . .private:. . .}; Sloth::Sloth(){. . .} void Sloth::act(){if (...){add_history("eat");...}else{add_history("sleep");...}} int main(){Sloth sloth;sloth.act();cout << sloth.get_history() << endl;cout <<…arrow_forwardDeclaring a function that is not a member of a class C as a(n) to C allows that function to access all of C's private and protected members.arrow_forward
- An abstract class a. Cannot be used to declare pointers and references b. Has at least one pure virtual function c. Can be instantiated d. Cannot have any constructorsarrow_forwardmake the flowchart for this code plz abstract class StudentCalculation /ABSTRACTION/{abstract int totalStrength();abstract int fees();}class College{private String collegeName;private int rank;private String address;College(String name,int r,String add){collegeName = name;rank = r;address = add;}public void setName(String n){collegeName = n;}public String getName(){return(collegeName);}public void setRank(int r){rank = r;}public int getRank(){return(rank);}public void setAddress(String a){address = a;}public String getAddress(){return address;}}class Deptcse extends StudentCalculation /INHERITENCE/{private int numberOfTeachers, numberOfMale, numberOfFeamle;Deptcse(int t,int m, int f){numberOfTeachers=t;numberOfMale = m;numberOfFeamle = f;}public String getName(){return("Computer Science and Engineering");}public void setTeacher(int t){numberOfTeachers=t;}public int getTeacher(){return(numberOfTeachers);}public void setMalestd(int m){numberOfMale = m;}public int…arrow_forwardGiven the definition of a class called Bag as following: class Bag { private: public: int items[100]; int itemCount; Bag(); bool add(int item); }; Please provide the implementation of the member function: int getLast() function returns the last number that was placed into the bag. Thisarrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr