Make an abstract class Number that allows the rest of the code to work correctly. printDoubled should be able to take either an Int or a Double and print out twice its value.
#include <iostream>
using namespace std;
//Do not modify anything on or above the line below this
//YOUR_CODE_BELOW
//YOUR_CODE
//YOUR_CODE_ABOVE
//Do not modify anything on or below the line above this
void printDoubled(const Number& n) {
cout << n.getValue() * 2 << endl;
}
class Int : public Number {
private:
int value;
public:
Int(int i) { value = i; }
double getValue() const { return value; }
};
class Double : public Number {
private:
double value;
public:
Double(double d) { value = d; }
double getValue() const { return value; }
};
int main()
{
Int n1(2);
Double n2(1.5);
printDoubled(n1);
printDoubled(n2);
}
#include <iostream>
using namespace std;
//Do not modify anything on or above the line below this
//YOUR_CODE_BELOW
//YOUR_CODE
class Number {
public:
virtual double getValue() const = 0;
};
//YOUR_CODE_ABOVE
//Do not modify anything on or below the line above this
void printDoubled(const Number& n) {
cout << n.getValue() * 2 <<
endl;
}
class Int : public Number {
private:
int value;
public:
Int(int i) { value = i; }
double getValue() const { return value; }
};
class Double : public Number {
private:
double value;
public:
Double(double d) { value = d; }
double getValue() const { return value; }
};
int main()
{
Int n1(2);
Double n2(1.5);
printDoubled(n1);
printDoubled(n2);
}


Make an abstract class Number that allows the rest of the code to work correctly. printDoubled...
Formulate the Math class so that it is not possible to create or make copies of objects of the class Math. According to the instruction, it shouldn't be possible to create or make copies of objects of the Math class. #include<iostream> using namespace std; class Math { public: static const double pi; static const double root2; }; const double Math::pi = 3.1416; const double Math::root2 = 1.4142; int main() { cout << "pi value : " << Math::pi << endl;...
Pure Abstract Base Class Project. Define a class called BasicShape which will be a pure abstract class. The class will have one protected data member that will be a double called area. It will provide a function called getArea which should return the value of the data member area. It will also provide a function called calcArea which must be a pure virtual function. Define a class called Circle. It should be a derived class of the BasicShape class. This...
I have to type and explain in class each code in every detail filled with // commentary. Explains how does work in every codes. 1) What does the below print #include <iostream> using namespace std ; int main() { int var1 = 20 ; int var2 = 30 ; int* ptr1 ; int* ptr2 ; int* temp ; ptr1 = &var1 ; ptr2 = &var2 ; cout << *ptr1 << endl ;...
what is the output for the following code? explain the steps. /*#include <iostream> using namespace std; int f(int &i) { i = 10; return(5 * i); } int main() { int n = 5; f(n); cout << n << "\n"; return 0; } #include <iostream> using namespace std; int sub1(int n) { n--; return n; } int main() { int m = 10; for(int j = 0; j < 10; j++) m -= sub1(j); cout << m << "\n"; return...
Hello I have a question. I would like to check if the code follows this requirement. Rectangle.h - A complete Rectangle Class including both declaration and definition appRectangle,cpp separate in two different files the class definition and implementation Code: rectangle.h // Rectangle class declaration. class Rectangle { private: double width; double length; public: void setWidth(double); void setLength(double); double getWidth() const; double getLength() const; double getArea() const; }; //************************************************** // setWidth assigns a value to the width member. * //************************************************** void...
The program has errors. Identify and make the necessary changes to make the program work. Remember to follow the rules of functions and arrays. Here is the expected output Total = 20 Average = 15 Area = 150 Area = 70 Enter a value: 10 Value 1 entered = 10 Enter an integer: 20 Value 2 entered = 20 Enter an integer: 30 Value 3 entered = 30 .................................................................. #include <iostream> using namespace std; void total(int, int, int); double average(int...
Finish the class Matrix.h: class Matrix { public: Matrix(); //default constructor ~Matrix(); //destructor Matrix(const Matrix &); //copy constror Matrix(int row, int col); Matrix operator+(const Matrix &)const; //overload operator“+” Matrix& operator=(const Matrix &); //overload operator“=” Matrix transpose()const; //matrix transposition void display()const; //display the data private: int row; //row int col; //column int** mat; //to save the matrix }; //main.cpp #include <iostream> #include"Matrix.h" using namespace std; int main() { int row, col; cout << "input the row and the col for Matrix...
C++ 15.15 Lab: Abstract base class Base Class The base Character class is located Character.h and cannot be changed. enum HeroType {WARRIOR, ELF, WIZARD}; const double MAX_HEALTH = 100.0; class Character { protected: HeroType type; string name; double health; double attackStrength; public: Character(HeroType type, const string &name, double health, double attackStrength); HeroType getType() const; const string & getName() const; /* Returns the whole number of the health value (static_cast to int). */ int getHealth() const; void setHealth(double h); /* Reduces...
How would I test this code thoroughly in a main.cpp file. Locomotive is an abstract base class. steam and dieselElectric are the derived classes. #ifndef COMMODITY_H #define COMMODITY_H #include <iostream> #include <string> using namespace std; class commodity { private: string name; int quantity; public: commodity(commodity *c); commodity(string name,int quantity); ~commodity(); string getName() const; int getQuantity() const; }; #endif #include "commodity.h" commodity::commodity(commodity *c) { this->name=c->getName(); this->quantity=c->getQuantity(); } commodity::commodity(string name,int quantity) { this->name=name; ...
C++ Language I have a class named movie which allows a movie object to take the name, movie and rating of a movie that the user inputs. Everything works fine but when the user enters a space in the movie's name, the next function that is called loops infinetly. I can't find the source of the problem. Down below are my .cpp and .h file for the program. #include <iostream> #include "movie.h" using namespace std; movie::movie() { movieName = "Not...