Hi this is a uni assignment What I have to do in parta is: Using the Kouti class declaration write main() code that -initialize the value of variable ogkos to 0.0 (in this variable the volume of each box will be stored that will be calculated later) -It will initialize KoutiA with values 2.0, 3.2, and 6.0 -It will initialize KoutiB with values 2.5, 4.0, and 5.0 -the volume of boxA will be calculated and saved in variable ogkos and then displayed on screen -the volume of boxB will be calculated and saved in variable ogkos and then displayed on screen
Here is the class declaration
class Kouti
{
public:
double length;
double breadth;
double height;
};
I have done so far parta. Here is my code:
#include <iostream>
using namespace std;
class Kouti
{
public:
//constructor that initialize Box dimensions
explicit Kouti(double lengthOfKouti, double breadthOfKouti,
double heightOfKouti)
: length(lengthOfKouti), breadth(breadthOfKouti),
height(heightOfKouti)
{
//empty body
}
double length;
double breadth;
double height;
double ogkos = 0.0;
/*
void displayMessage() const
{
cout << "Welcome to the Kouti program!" << endl;
}
*/
/*
void calculateOgkos() const
{
ogkos = length*breadth*height;
cout << ogkos;
}
*/
};
int main()
{
Kouti KoutiA(2.0, 3.2, 6.0);
Kouti KoutiB(2.5, 4.0, 5.0);
KoutiA.ogkos = KoutiA.length*KoutiA.breadth*KoutiA.height;
KoutiB.ogkos = KoutiB.length*KoutiB.breadth*KoutiB.height;
// Display the volume of each box
cout << "KoutiA volume is: " << KoutiA.ogkos
<< "\nKoutiB volume is: " << KoutiB.ogkos
<< endl;
return 0;
}
It seems to be working fine It gives me a warning though about non-static data member initializers only available with -std=c++11 or -std=gnu++11. Iam using code blocks
Partb
In partb I have to do the following: Convert the class member data to private and provide the appropriate public function calculateOgkos() that will calculate the volume of each object. Do in main() the appropriate changes so that it works as in parta. Can you help me on that?
Also something not related... I have been trying to register with codeblocks forum but I don't get the activation email. I have tried several times. thanks
Aucun commentaire:
Enregistrer un commentaire