Hello,
Below is my prompt and my attempt at fixing the problem. When trying to run my code, the following error messages pop up:
LINE 53
expected an identifier
expression must have a constant value
variable "b" is not a type name
variable "m" is not a type name
variable "l" is not a type name
variable "w" is not a type name
syntax error: '.'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"You should have a class called Skateboard where Skateboard has 3 public member variables (refer to Ex 27 for details). You don’t need the previous code for the main function. Remove it and make a clean main function to start with.
1) Add 1 more public double member variable called width.
2) Modify print member function to print each element of the Skateboard class, now including width.
3) Write 2 constructors as follows:
default constructor (has NO input parameter) with member initialization list that initializes the brand and model with “NA”, and length and width to -1.0. Since this uses a member initialization list, there shouldn’t be any statements inside the body. 2nd constructor overloaded with 4 parameters for the skateboard brand, model, length, and width, in that order. The constructor will initialize all of the member variables and will accept values for these parameters. Also this should have an empty body; the assignments should be done in the header."
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
#include <iostream>
#include <string>
using namespace std;
class Skateboard {
public:
Skateboard();
Skateboard(string b, string m, double l, double w);
void print() {
cout << "brand: " << brand << " ";
cout << "model: " << model << " ";
cout << "length: " << length << " ";
cout << "width: " << width << " ";
}
bool isLongBoard() {
if (length > 28)
return true;
else
return false;
}
private:
string brand, model;
double length, width;
};
Skateboard::Skateboard() {
brand = "NA";
model = "NA";
length = -1.0;
width = -1.0;
return;
}
Skateboard::Skateboard(string b, string m, double l, double w) {
brand = b;
model = m;
length = l;
width = w;
}
int main() {
string b, m;
double l, w;
int i;
Skateboard skateboardCollection[8];
for (i = 0; i<2; i++) {
cin >> b;
cin >> m;
cin >> l;
cin >> w;
Skateboard.skateboardCollection[i](b, m, l, w);
}
for (i = 0; i<2; i++) {
skateboardCollection[i].print();
if (skateboardCollection[i].isLongBoard() == true)
cout << "isLongBoard: 1 ";
else
cout << "isLongBoard: 0 ";
}
system("pause");
return 0;
}
| |