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
Web Development and Design Foundations with HTML5 (8th Edition)
Introduction To Programming Using Visual Basic (11th Edition)
Starting Out With Visual Basic (8th Edition)
SURVEY OF OPERATING SYSTEMS
Management Information Systems: Managing The Digital Firm (16th Edition)
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
- in c++ write aprogram to Create a class Rectangle with length and breadth as private data members and also provide the following member functions: getdata(): gets the length and breadth of rectangle. calarea(): return the area of the rectangle. calperi(): return the perimeter of the rectangle. issquare(): return true if the rectangle is squarearrow_forwardData Structuresarrow_forwardclass A {protected int x1,y1,z; public: A(a, b,c):x1(a+2),y1(b-1),z(c+2) { for(i=0; i<5;i++) x1++; y1++;z++;}}; class B {protected: int x,y; public: B(a,b):x(a+1),y(b+2) { for(i=0; i<5;i++) x+=2; y+=1;}}; class D:public B, virtual public A { private: int a,b; public: D(k,m,n): a(k+n), B(k,m),b(n+2),A(k,m,n) { a=a+1;b=b+1;}}); int main() {D ob(4,2,5);} what the values of x1,y1 and zarrow_forward
- Activity - 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_forwardImplement 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_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_forwardModify and rewrite the Food class to an abstract class, so that no instance of Food class can be createdarrow_forwardAll virtual functions in an abstract base class must be declared as pure virtual functions T/Farrow_forward
- CONSTRUCTOR// 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_forwardAn 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_forwardclassarrow_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