What will the following
#include <iostream>
using namespace std;
class First
{
protected:
int a:
public:
First(int x = 1)
{ a = x; }
virtual void twist()
{ a * = 2; }
int getVal ()
{ twist(); return a; }
}:
class Second : public First
{
private:
int b:
public:
Second(int y = 5)
{ b = y; }
virtual void twist()
{ b *= 10: }
};
int main()
{
First object-1;
Second object2;
cout ≪ object1.getVal () ≪ endl;
cout ≪ object2.getVal() ≪ endl;
return 0;
Want to see the full answer?
Check out a sample textbook solutionChapter 15 Solutions
Starting Out with C++ from Control Structures to Objects (8th Edition)
Additional Engineering Textbook Solutions
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Starting Out With Visual Basic (8th Edition)
Starting out with Visual C# (4th Edition)
Starting Out with Python (4th Edition)
C How to Program (8th Edition)
Starting Out with Java: Early Objects (6th Edition)
- //Please Fix this program #include<iostream>using namespace std;class Point{private:int x, y;public:Point() {}Point(int x1, int y1) { x = x1; y = y1; }Point(const Point &p1) {x = p1.x; y = p1.y; } // Copy constructorint getX() { return x; }int getY() { return y; }};int main(){Point p0(); // Calling Default ConstructorPoint p1(10, 15); // Calling Parameterized constructorPoint p2 = p1; // Calling Copy constructorcout << "p0.x = " << p0.getX() << ", p0.y = " << p0.getY();cout << "p1.x = " << p1.getX() << ", p1.y = " << p1.getY();cout << "\np2.x = " << p2.getX() << ", p2.y = " << p2.getY();return 0;}arrow_forwardQuestion 15 1(8).png public class numClass { private int a; private static int y = 10; public numClass(int newx) {a-newx; } public void set(int newx) {a=newx; y+=a;} public void setY(int newY) {y-newY; } public static int getY() { return y; } // end of class Blank 1 Blank 1 Add your answer public class output[ public static void main(String[] args) { numclass one new numClass(10); numclass two new numClass (2); try{ one.sety(30); two.set(4); if(one.getY()-30) throw new Exception ("30"); one. sety (40); } catch(Exception e) { two.setY(50); } System.out.println(two.getY()); // end of main } // end of class ***arrow_forwardIndicate each error or mistake in this codearrow_forward
- interface StudentsADT{void admissions();void discharge();void transfers(); }public class Course{String cname;int cno;int credits;public Course(){System.out.println("\nDEFAULT constructor called");}public Course(String c){System.out.println("\noverloaded constructor called");cname=c;}public Course(Course ch){System.out.println("\nCopy constructor called");cname=ch;}void setCourseName(String ch){cname=ch;System.out.println("\n"+cname);}void setSelectionNumber(int cno1){cno=cno1;System.out.println("\n"+cno);}void setNumberOfCredits(int cdit){credits=cdit;System.out.println("\n"+credits);}void setLink(){System.out.println("\nset link");}String getCourseName(){System.out.println("\n"+cname);}int getSelectionNumber(){System.out.println("\n"+cno);}int getNumberOfCredits(){System.out.println("\n"+credits); }void getLink(){System.out.println("\ninside get link");}} public class Students{String sname;int cno;int credits;int maxno;public Students(){System.out.println("\nDEFAULT constructor…arrow_forwardFinish the Java code: Code: class Tile{char letter;int value; //ConstructorTile(char l, int v){letter = l;value = v;} //The function returns value of data member value.public int getValue(){return value;}//The function returns value of data member letter.public char getLetter(){return letter;} //the function return string for value and letterpublic String toString(){return(letter + " with value " + value);} //The function checks for equality of two objects.public boolean equals(Tile t){if(this.letter == t.letter && this.value == t.value)return true;elsereturn false;} } Output: The word HELLO is worth 8 points Its tile with the highest value is: H with value: 4 You have used a total of 5 tiles so far.arrow_forwardC++ Define and implement a class named Movie with the following members: std::string name; float cost; bool signedByDirector; Movie(); Movie(std::string movietitle); std::string getName (); float getCost(); void setCost (float newCost); // Price is modified by signing (see description) // Change cost to newCost // Returns signedByDirector bool issigned (); void signMovie(); Ensure each variable and function has been set an appropriate access modifier and your header file includes a header guard. Your methodgetCost() should return cost, but if the Movie is signed, it should return the cost plus a markup of 20%. For example, if a movie was worth $100, getCost () should return 100. If the same movie was signed by the author, then getCost() should return 120. Note: This function should not modify the class member cost, instead it should use cost and signedByDirector to determine the actual cost/value of the Movie. Your default constructor should set the cost to 0, the title to "NO TITLE".…arrow_forward
- Programming Exercise 11-2 dateType.h file provided #ifndef date_H #define date_H class dateType { public: void setDate(int month, int day, int year); //Function to set the date. //The member variables dMonth, dDay, and dYear are set //according to the parameters //Postcondition: dMonth = month; dDay = day; // dYear = year int getDay() const; //Function to return the day. //Postcondition: The value of dDay is returned. int getMonth() const; //Function to return the month. //Postcondition: The value of dMonth is returned. int getYear() const; //Function to return the year. //Postcondition: The value of dYear is returned. void printDate() const; //Function to output the date in the form mm-dd-yyyy. bool isLeapYear(); //Function to determine whether the year is a leap year. dateType(int month = 1, int day = 1, int year = 1900); //Constructor to…arrow_forward#include <iostream> using namespace std; class Rectangle { // define class public: Rectangle() { length = 0; width = 0; } // constructor float getlength() { return length; } // return length float getWidth() { return width; } // return width float area() { return length* width; } // return area float perimeter() { return 2 * length + 2 * width; } void setValues(float, float); private: float length, width; }; void Rectangle::setValues(float len, float wid) { if (len <= 0 || len >= 20) { cout << "Enter new value for length "; cin >> len; } length = len; if (wid <= 0 || wid >= 20) { cout << "Enter new value for width "; cin >> wid; } width = wid; } int main() { float length, width; Rectangle r; cout << "Enter a value for length and width between 0 and…arrow_forward// volunteer.h #include class Volunteer { public: Volunteer () { } std::string Name () void SetName (const private: std::string name_; }; const { return name_; } std::string& name) { name_ = name; }arrow_forward
- C++arrow_forwardTake the following code: class Song { private: string name; string author; string genre; int year_released; public: Song() { /* initialize attributes */} string get_name() { return name; } void set_name(string new_name) { name = new_name; } string get_author() { return author; } void set_author(string new_author) { author = int get_age(int curr_year) { return curr_year - year_released; new_author; } } void set_year_released(int new_year) { year_released = new_year ; } }; indicate the methods of this class. Insert Format Tools Table Edit View в IU д 12pt v Paragraph varrow_forwardTerm by CodeChum Admin (JAVA CODE) Construct a class called Term. It is going to represent a term in polynomial expression. It has an integer coefficient and an exponent. In this case, there is only 1 independent variable that is 'x'. There should be two operations for the Term: public Term times(Term t) - multiplies the term with another term and returns the result public String toString() - prints the coefficient followed by "x^" and appended by the exponent. But with the following additional rules: if the coefficient is 1, then it is not printed. if the exponent is 1, then it is not printed ( the caret is not printed as well) if the exponent is 0, then only the coefficient is printed. Input The first line contains the coefficient and the exponent of the first term. The second line contains the coefficient and the exponent of the second term. 1·1 4·3 Output Display the resulting product for each of the test case. 4x^4arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education