Ship Problem

You guys probably noticed by now that this is my third question in a row lol. Sorry about that but I decided to work on as much different problems as I can and when I get stuck I posted those online so I can wait on those while I work on other problems. Messy time management on my part haha :)

So I managed to create both the header files and the cpp files but for some reason it wont accept the arguments I'm trying to pass. I double checked my codes for hours and I can't seem to figure out why.. Thanks guys.

"error C2661: 'CruiseShip::CruiseShip' : no overloaded function takes 3 arguments"

"IntelliSense: no instance of constructor "CruiseShip::CruiseShip" matches the argument list"

Ship 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
#pragma
#ifndef Ship_H
#define Ship_H
#include <string>

using namespace std;

class Ship
{
protected:
	string Name;
	string Year;
public:
	Ship()
	{ Name = ""; Year = "";}

	Ship(string N, string Y)
	{ Name = N; Year = Y;}

	void setN(string N)
	{ Name = N;}

	void setY(string Y)
	{ Year = Y;}

	string getN() const
	{return Name; }

	string getY() const
	{return Year; }

	void print()
	{ return cout << "The name of the ship is " << Name << " and it was built on " << Year << endl;}
};

#endif Ship_H 


Cargo Ship 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
#pragma
#ifndef CargoShip_H
#define CargoShip_H
#include "Ship Header.h"

class CargoShip : public Ship
{
protected:
	int Tonnage;
public:
	CargoShip() : Ship()
	{ Tonnage = 0;}

	CargoShip(int T) : Ship()
	{ Tonnage = T;}

	void setT(int T)
	{ Tonnage = T;}

	int getT() const
	{ return Tonnage;}

	void print()
	{ return cout << "The name of the ship is " << Name << " and it has a cargo capacity of " << MaxPas << " tons." << endl;}
};

#endif CargoShip_H 


Cruise Ship 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
#pragma
#ifndef CruiseShip_H
#define CruiseShip_H
#include "Ship Header.h"

class CruiseShip : public Ship
{
protected:
	int MaxPas;
public:
	CruiseShip() : Ship()
	{ MaxPas = 0;}

	CruiseShip(int MP) : Ship()
	{ MaxPas = MP;}

	void setMP(int MP)
	{ MaxPas = MP;}

	int getMP() const
	{ return MaxPas;}

	void print()
	{ return cout << "The name of the ship is " << Name << " and it can carry up to " << MaxPas << " people." << endl;}
};

#endif CruiseShip_H 


CPP File
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <iomanip>
#include "CargoShip Header.h"
#include "CruiseShip Header.h"

using namespace std;

int main()
{
	const int NUM_SHIPS = 3;
	Ship *ships[NUM_SHIPS] = 
	{	new Ship ("Baccardi", "January 18th 1991"),
		new CruiseShip (300, "Chardonnay", "Januarty 19th 1991"),
		new CargoShip (1000, "Patron", "January 21st 1991")
	};

};


thanks again for reading.
You need to add in constructors for 2nd and 3rd parameters. Here is an example for the cruise ship:
1
2
3
4
5
6
class CruiseShip : public Ship {
    public:
        CruiseShip(int MP = 0, std::string Name = "", std::string Year = "")
            : Ship(Name, Year), MaxPas(MP) {}
        // ...
}


Note I have used default arguments: If the user doesn't input that argument, then the default parameter (an empty string) is used instead.
thanks NT3, I fixed that problem.

This is my new CPP file
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
#include <iostream>
#include <iomanip>
#include "CargoShip Header.h"
#include "CruiseShip Header.h"

using namespace std;

void displayShip(const Ship *);

int main()
{
	const int NUM_SHIPS = 3;
	Ship *ships[NUM_SHIPS] = 
	{	new Ship ("Baccardi", "January 18th 1991"),
		new CruiseShip (300, "Chardonnay", "January 19th 1991"),
		new CargoShip (1000, "Patron", "January 21st 1991")
	};

	for (int count = 0; count < NUM_SHIPS; count ++)
	{
		displayShip(ships[count]);
	}
	

cin.ignore();
cin.get();
return 0;
};

void displayShip(const Ship *Ships)
{
	cout << "The name of the ship is " << Ships -> getN();
	cout << Ships -> Print1() << Ships -> getY() << endl;
};


I changed the print() accessor function in Ship's to...
1
2
	string Print1() const
	{return " and it was built on ";}


while the other ship's had their own string definitions..

However, when the program runs it only shows the respective ship's names and year but not the new value added in? "300" and "1000"

How can I get around to showing that? I'm really stumped.
Do you have any code to actually print out the numbers? If so, please show us so we can see if you have any problems.
This one is for the cargo ship..
1
2
3
4
5
	string Print1() const
	{ return " and it has a cargo capacity of ";}

	string Print2() const
	{ return " tons.";}


and this is for the cruise ship...
1
2
	string Print1() const
	{ return " and it has a passanger capacity of ";}


I have the "getfunctions" shown in my first posts to show the numbers
Last edited on
You are never calling Print2() as far as I can see. Maybe that is what your problem is? Also, does it access the numbers themselves somewhere? Also, you aren't calling getT() either... try adding these functions to your printing statements where you do the actual printing.
Topic archived. No new replies allowed.