Question

complete the following tasks in C++ code: #include <iostream> using namespace std; class Cube{ public: Cube(int,...

complete the following tasks in C++ code:

#include <iostream>
using namespace std;
class Cube{
  public:
    Cube(int, int,int);
    int getVolume();
  private:
   int height;
   int weight;
   int depth;
};
Cube::Cube(int h, int w, int l)
{
    height = h;
    weight = w;
    depth = l;

}
int main(){

}

Homework Answers

Answer #1
#include <iostream>

using namespace std;

class Cube {
public:
    Cube(int, int, int);

    int getVolume();

private:
    int height;
    int weight;
    int depth;
};

Cube::Cube(int h, int w, int l) {
    height = h;
    weight = w;
    depth = l;
}

int Cube::getVolume() {
    return height * weight * depth;
}

int main() {
    int h, w, l;
    cout << "Enter height of cube: ";
    cin >> h;
    cout << "Enter width of cube: ";
    cin >> w;
    cout << "Enter length of cube: ";
    cin >> l;
    Cube c(h, w, l);
    cout << "Volume of the cube is " << c.getVolume() << endl;
    return 0;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
How to trace a c++ program by hand #include<iostream> using namespace std;    class Test {...
How to trace a c++ program by hand #include<iostream> using namespace std;    class Test {     int value; public:     Test(int v); };    Test::Test(int v) {     value = v; }    int main() {     Test t[100];     return 0; } _______________ #include <iostream> using namespace std; int main() { int i,j; for (i=1; i<=3; i++) { for(j=1; j<=i; j++ ) { cout<<"*"; } cout << "\n";   } return 0; }
What is value ofmyInt? #include <iostream> using namespace std; int main() {    int myInt;   ...
What is value ofmyInt? #include <iostream> using namespace std; int main() {    int myInt;    int* myScore;    int myVar;       myInt = 10;    myScore = &myInt;    myVar = 20;    myVar = *myScore;    *myScore = 30;    myVar = 40;    myVar = *myScore;    } Group of answer choices 30 20 10 0
This code it's not working, fix it for me please #include <iostream> using namespace std; class...
This code it's not working, fix it for me please #include <iostream> using namespace std; class People {    string name;    double height; public:    void setName(string name)    {        this->name = name;    }    void setHeight(double height)    {        this->height = height;    }    double getHeight() {        return height;    }    string getName()    {        return name;    } }; int main() {    const int size...
/* Displaying process segment addresses */ #include <iostream> extern int etext, edata, end; using namespace std;...
/* Displaying process segment addresses */ #include <iostream> extern int etext, edata, end; using namespace std; int main( ){ cout << "Adr etext: " << hex << int(&etext) << "\t "; cout << "Adr edata: " << hex << int(&edata) << "\t "; cout << "Adr end: " << hex << int(&end ) << "\n"; return 0; } please modify this above code and execute to get the output.
C ++ #include <fstream> #include <iostream> using namespace std; int main() { float bmi; ifstream inFile;...
C ++ #include <fstream> #include <iostream> using namespace std; int main() { float bmi; ifstream inFile; inFile.open("bmi.txt"); while (!inFile.eof()) { inFile >> bmi; if( bmi < 18.5) { cout << bmi << " is underweight " ; } else if( bmi >= 18.5 && bmi <= 24.9) { cout << bmi << " is in normal range " ; } else if( bmi >= 25.0 && bmi <= 29.9) { cout << bmi << " is overweight " ; }...
in C++ Need a heap-sort function #include <iostream> #include <stdlib.h> #include <string> using namespace std; void...
in C++ Need a heap-sort function #include <iostream> #include <stdlib.h> #include <string> using namespace std; void MyFunc ( int *array ) { // Your code here ----------------- } int main(int argc,char **argv) { int *Sequence; int arraySize; // Get the size of the sequence cin >> arraySize; // Allocate enough memory to store "arraySize" integers Sequence = new int[arraySize];    // Read in the sequence for ( int i=0; i<arraySize; i++ ) cin >> Sequence[i]; // Run your algorithms to...
Quick sort func in C++ #include <iostream> #include <stdlib.h> #include <string> using namespace std; void MyFunc...
Quick sort func in C++ #include <iostream> #include <stdlib.h> #include <string> using namespace std; void MyFunc ( int *array ) { // Code here } int main(int argc,char **argv) { int *Sequence; int arraySize; // Get the size of the sequence cin >> arraySize; // Allocate enough memory to store "arraySize" integers Sequence = new int[arraySize];    // Read in the sequence for ( int i=0; i<arraySize; i++ ) cin >> Sequence[i]; // Run your algorithms to manipulate the elements...
c++ Complete the constructor Complete the constructor of Car, child class of Vehicle, to correctly assign...
c++ Complete the constructor Complete the constructor of Car, child class of Vehicle, to correctly assign the parameters (m and y) to the attributes maker and year. #include <iostream> using namespace std; class Vehicle { private: string maker; int year; public: Vehicle(string m, int y):maker(m),year(y){}; string getMaker() { return maker; }; int getYear() { return year; }; }; class Car : public Vehicle { private: string model; public: Car(string m, int y, string md) //COMPLETE CONSTRUCTOR { model = md;...
C++ question. Must use #include <iostream> and "using namespace std;" You must also have only a...
C++ question. Must use #include <iostream> and "using namespace std;" You must also have only a .cpp and .h file Define a class called Rectangle that can store the height and width of a rectangle as instance variables, has a constructor that allows you to set the height and width when you create a Rectangle, a default constructor that sets both height and width to 0, and functions to return the following values: * the perimeter [ which should be...
#include <iostream>using namespace std;int main(){ char meal_choice; //user's choice int servings, total_calories; // Display greeting: cout...
#include <iostream>using namespace std;int main(){ char meal_choice; //user's choice int servings, total_calories; // Display greeting: cout << "Welcome to the Calorie Count-ulator!\n"; // Get user input: cout << "Enter your meal choice ([P]izza, [S]alad, [H]amburger)\n"; cin >> meal_choice; cout << "Enter the amount of servings (1-9):\n"; cin >> servings; // TODO: Use a switch statement to evaluate the user's meal choice // Handle error checking where appropriate // Exit the program: return 0;}
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT