Find the error(s) in the following code: (6)
Want to see the full answer?
Check out a sample textbook solutionChapter 13 Solutions
EBK C++ PROGRAMMING: FROM PROBLEM ANALY
- a) Given the following code segments: class MyClass { String name; double value; MyClass (String n, double v) { name = n; value =v; } String getName () { return name; } double getValue () { return value; } } (i) Explain what is immutable object.arrow_forwardConsider the following class: public class theClass { private double value; private string str; public static int count; public theClass () { } public theClass (double d, int, x, String s) { } public void print() { } public static void incrementCount() { } } a) How many members do class theClass have? b) Compare the purpose of the two constructors. c) Use the reference this to write the definition of a method print( )to output the value of the instance data members separated by commas. d) Write a statement to create an object myClass of the class theClass and initialise the instance variables to 5, 10.75 and the string Class. e) Write a definition (heading) for a copy constructor for the class.arrow_forwardIn-class Assignment Day 8 You should draw the hierarchy for your classes to understand how the coding should be structured. Be sure to notate any classes that are abstract. Write an abstract class for Shape. The intended subclasses are Polygon, Circle, Triangle, and Rectangle. All of these will have a name, an area, and a perimeter. (Consider which methods might be abstract.) Add a toString method that will return the information about the Shape, for example: Triangle, Area: 7.5, Perimeter: 12.0 Write the class Rectangle. A Rectangle is a Shape and should have a width and a height. When a Rectangle is outputted, it should read: Rectangle, Length: #, Width: #, Area: #, Perimeter: # Write the class for Circle. Every circle is a Shape that has a radius. Be sure to provide an accessor method (getter) for the radius. When a circle is outputted, it should read: Circle, Radius: #, Area: #, Circumference: # Write a TestShape class that has the main method, which creates…arrow_forward
- Class definitionDefine a class bankAccount to implement the basic properties of a bank account. Anobject of this class should store the following data: Account holder’s name (string) Account number (int) Account type (string, check/savings/business) Balance (double) Interest rate (double) – store interest rate as a decimal number. Add appropriate member functions to manipulate an object. Use a static member in theclass to automatically assign account numbers.arrow_forwardDetermine if this statement is true or false Take the following method, which is defined in some class: class SomeClass: SomeBaseClass{ private int override MyMethod() { //do something.... } } This is an example of run time polymorphism, as MyMethod is being redefined in the child class by the override keyword.arrow_forwardclass Base { public: int x, y: public: Base(int i, int j) { x = i; y = j; }}; class Derived : public Base public: Derived (int i, int j) { x = i; y = j; void display() {cout « x <<" "<< y; }}; int main(void) { Derived d(5, 5); d.display(); return e; Error O X=5,Y=5 X-0,Y=0 None of the above Other:arrow_forward
- class 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_forwardQUESTION 16 What must be true of a class with one abstract method? O The class must also implement the Iterable interface Any derived class must implement the method The abstract method must have the static modifier O The method cannot specify a return value QUESTION 17 Suppose we wanted to design a set of classes for a veterinarian's office. Our Customer class looks like this: public class Customer { Pet [] pets; } Select all the statements that are true Once the size of the pets array has been set, it cannot be changed Because we're using an array, all pets must be the same A customer must have at least one pet We also need to declare a Pet class QUESTION 18 What is the proper use of an enumeration? To define a set of ordered values To enforce the use of the Comparable interface O To define, or enumerate, the values returned by a Random object generator O To define the classes in an inheritance hierarchyarrow_forwardFind the error in each of the following code segments: // Superclasspublic class Vehicle{private double cost;(Other methods . . .)}// Subclasspublic class Car extends Vehicle{public Car(double c){cost = c;}}arrow_forward
- class GradedActivity { private: double score; public: GradedActivity() { score = 0.0; } GradedActivity(double s) { score = s; } void setScore(double s) { score = s; } double getScore() { return score; } char getLetterGrade() const; }; Implement the GradedActivity class above. In this C++ assignment, create a new class Assignment which is derived from GradedActivity. It should have three private member ints for 3 different parts of an assignment score: functionality (max 50 points), efficiency (max 25 points), and style (max 25 points). Create member function set() in Assignment which takes three parameter ints and sets the member variables. It should also set its score member, which is inherited from GradedActivity, using the setScore() function, to functionality + efficiency + style. Signature: void Assignment::set(int, int, int) Create a main program which instantiates an Assignment, asks the user…arrow_forward15. Suppose the class Employee is declared as follows: public class Employee { private String name; private double baseSalary: public void setName(String newName) {...} public void setBasSalary(double newSalary){...} public String getName() {...} public double getSalary({...} } a)Declare a class Manager that inherits from the class Employee and adds an instance variable bonus for storing a salary bonus. Omit constructors and methods. ANS: b) Which instance variables does the Manager class have? c) In the manager class, provide the method overrides the getSalary method from the class Employee so that it returns the sum of the salary and the bonus d) Based on the above question, which methods does the manager class inherit? e) In the manager class, override the getName method so that managers have a before their name (such as *John Smith).arrow_forward3. Person and Customer Classes The Person and Customer Classes Write a class named Person with data attributes for a person’s name, address, and telephone number. Next, write a class named Customer that is a subclass of the Person class. The Customer class should have a data attribute for a customer number, and a Boolean data attribute indicating whether the customer wishes to be on a mailing list. Demonstrate an instance of the Customer class in a simple program.arrow_forward
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
- 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