C++
Could you check my code, it work but professor said that there are some mistakes(check virtual functions, prin() and others, according assignment) .
Assignment:
My code:
#include<iostream>
#include<string>
using namespace std;
class BasicShape { //Abstract base class
protected:
double area;
private:
string name;
public:
BasicShape(double a, string n) {
area=a;
name=n;
}
void virtual calcArea()=0;//Pure Virtual Function
virtual void print() {
cout<<"Area of "<<getName()<<" is: "<<area<<"\n";
}
string getName(){
return name;
}
};
class Circle : public BasicShape {
private:
double radius;
public:
Circle(double a, string n, double r): BasicShape(a,n) {
radius=r;
}
void calcArea() {
area = 3.14159*radius*radius; //use include math for pi and pow
}
void print() {
cout<<"Radius is: "<<radius<<" and area is
"<<BasicShape::print()<<"of
"<<getName()<<"\n";
}
};
void poly(BasicShape *bs) {
bs->calcArea();
bs->print();
}
int main() {
Circle c(0,"Round", 10);
poly(&c);
cout<<"\n\n";
return 0;
}
#include <iostream>
using namespace std;
class BasicShape
{
//a) Protected Member Variable: area (a double used to hold the shape’s area).
protected:
double area;
//b) Private Member Variable: name (a string to indicate the shape’s type)
private:
string name;
public:
//BasicShape(double a, string n): A constructor that sets value of member area with a and member name with n.
BasicShape(double a, string n)
{
area = a;
name = n;
}
//calcArea(): This public function should be a pure virtual function.
virtual void calcArea() = 0;
//print(): A public virtual function that only prints the value of data member area.
virtual void print()
{
cout<<"Area: "<<area<<endl;
}
//getName():A public function that returns the value of data member name.
string getName()
{
return name;
}
};
C++ Could you check my code, it work but professor said that there are some mistakes(check...
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...
4.a) 4.b> 4.c) C++ Programming Lab Exercise 09 Inheritance. Friend Functions, and Polymorphism (virtual functions) 4.a) Run the following code and observe the output. #include <iostream> #include <string> using namespace std; class Vehicle public: void print() { cout << "Print: I am a vehicle. \n"; } void display() { cout << "Display: I am a vehicle. \n"; } }; class Car: public Vehicle { public: void print() { cout << "Print: I am a car.\n"; } void display() { cout...
Ship, CruiseShip, and CargoShip Classes (in C++ language i use visual studios to code with) design a Ship class that has the following members: - A member variable for the name of the ship (a string) - A member variable for the year that the ship was built (a string) - A contsructor and appropriate accessors and mutators - A virtual print function that displays the ship's name and the year it was built (nobody seems to get this part...
c++ Part 1 Consider using the following Card class as a base class to implement a hierarchy of related classes: class Card { public: Card(); Card (string n) ; virtual bool is_expired() const; virtual void print () const; private: string name; Card:: Card() name = ""; Card: :Card (string n) { name = n; Card::is_expired() return false; } Write definitions for each of the following derived classes. Derived Class Data IDcard ID number CallingCard Card number, PIN Driverlicense Expiration date...
#include <iostream> using namespace std; class Circle{ // private member variable named radius private: double radius; // get function for radius public: double getRadius(){ return radius; } // set function for radius void setRadius(double rad){ radius=rad; } // returning area = 3.14159 * radius * radius double getArea(){ return (3.14159 * radius * radius); } }; // Sample run int main() { // Declaring object of Circle Circle myCircle; myCircle.setRadius(5); // printing radius of circle cout<<"Radius of circle is: "<<(myCircle.getRadius())<<endl;...
I have given you a piece of code to test that your circle class works correctly. Add your circle class to the code. public class Lab2Num1 { public static class Circle { private double radius; //your code goes here //provide default constructor, constructor with one parameter, area, and circumference } public static void main(String[] args) { Circle c = new Circle(1.5); System.out.printf("The circumference of a circle of radius " + c.getRadius()+ " is %5.2f\n", c.circumference()); System.out.printf("The area of...
Here is the code from the previous three steps: #include <iostream> using namespace std; class Student { private: //class variables int ID; string firstName,lastName; public: Student(int ID,string firstName,string lastName) //constructor { this->ID=ID; this->firstName=firstName; this->lastName=lastName; } int getID() //getter method { return ID; } virtual string getType() = 0; //pure virtual function virtual void printInfo() //virtual function to print basic details of a student { cout << "Student type: " << getType() << endl; cout << "Student ID: " << ID...
C++ -- Vector of Bank Accounts (15 pts) Please help! :( Use csegrid or Clion for this part Add on to the lab12a solution(THIS IS PROVIDED BELOW). You will add an overload operator function to the operator << and a sort function (in functions.h and functions.cpp) Print out the customer’s name, address, account number and balance using whatever formatting you would like Sort on account balance (hint: you can overload the < operator and use sort from the...
Please use C++. Write a class named Circle that has a double data member named radius and a static double data member named maxRadius. It should have a default constructor that initializes the radius to 1.0. It should have a constructor that takes a double and uses it to initialize the radius. It should have a method called calcArea that returns the area of the Circle (use 3.14159 for pi). It should have a static set method for the maxRadius....
solve it in c++ 10 note: please do not give me same answer like this 1. Define a Pet class that stores the pet's name, age, and weight. Add appropriate constructors, accessor functions, and mutator functions. Also define a function named getLifespan that returns a string with the value "unknown lifespan." Next, define a Dog class that is derived from Pet. The Dog class should have a private member variable named breed that stores the breed of the dog. Add...