Using Default and Second Constructs to Print an Info Log

Hello,
Below is the code I have created in attempts to fulfill the below prompt, but I cannot get this program to run.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You should have a class called Skateboard where Skateboard has 3 public member variables (stated in previous problem). 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.

Should print something like the example below:

brand: Sector12
model: Stepper
length: 22
isLongBoard: 0
brand: Jamboree
model: Hurricane
length: 30
isLongBoard: 1

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
#include <iostream>
#include <string>
using namespace std;

class Skateboard {
public:
        string brand, model;
	double length, width;
	BrandItem();
	BrandItem(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;
	}
};

	BrandItem::BrandItem() {
		brand = "N/A";
		item = -1;
		return;
	}

	BrandItem::BrandItem(string b, string m, double l, double w) {
		brand = b;
		model = m;
		length = l;
		width = w;
	}

int main() {
// original code in main of precursor problem	
/* BrandItem b, m, l, w;
	int i;
	Skateboard skateboardCollection[4];

	for (i = 0; i<3; i++) {
		cin >> b;
		cin >> m;
		cin >> l;
		cin >> w;
		skateboardCollection[i].BrandItem(b, m, l, w);
	}
	for (i = 0; i<3; i++) {
		skateboardCollection[i].print();
		if (skateboardCollection[i].isLongBoard() == true)
			cout << "isLongBoard: 1 ";
		else
			cout << "isLongBoard: 0 ";
	} */

	system("pause");
	return 0;
}
Constructors need to be named the same as the class.

When defining functions and other member functions you don't need to put ClassName:: in front (I think Microsoft allows this but it's actually an error according to the official rules of C++).
Last edited on
Topic archived. No new replies allowed.