I can't get the cpp file to read the print() files from the .h files... Please can somebody check it for me and see what is wrong...
This is the errors that I get when I try and Compile
1>------ Build started: Project: 12423297C++, Configuration: Debug Win32 ------
1> ShipDemo.cpp
1>c:\users\user\documents\visual studio 2010\projects\12423297c++\12423297c++\ship.h(33): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\user\documents\visual studio 2010\projects\12423297c++\12423297c++\cargo.h(25): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\user\documents\visual studio 2010\projects\12423297c++\12423297c++\cruise.h(25): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\user\documents\visual studio 2010\projects\12423297c++\12423297c++\shipdemo.cpp(22): warning C4099: 'Ship' : type name first seen using 'class' now seen using 'struct'
1> c:\users\user\documents\visual studio 2010\projects\12423297c++\12423297c++\ship.h(9) : see declaration of 'Ship'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Ship.h
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
|
#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; }
virtual print()
{
cout << "The name of the ship is " << Name << " and it was built on " << Year << endl;}
};
#endif Ship_H
|
Cruise.h
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
|
#pragma
#ifndef CruiseShip_H
#define CruiseShip_H
#include "Ship.h"
class CruiseShip : public Ship
{
protected:
int MaxPas;
public:
CruiseShip(int MP = 0, std::string Name = "", std::string Year = "")
: Ship(Name, Year), MaxPas(MP)
{ MaxPas = 0;}
CruiseShip(int MP) : Ship()
{ MaxPas = MP;}
void setMP(int MP)
{ MaxPas = MP;}
int getMP() const
{ return MaxPas;}
virtual print()
{
cout << "The name of the ship is " << Name << " and it can carry up to " << MaxPas << " people." << endl;
}
};
#endif CruiseShip_H
|
Cargo.h
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
|
#pragma
#ifndef CargoShip_H
#define CargoShip_H
#include "Ship.h"
class CargoShip : public Ship
{
protected:
int Tonnage;
public:
CargoShip(int T = 0, std::string Name = "", std::string Year = "")
: Ship(Name, Year), Tonnage(T)
{ Tonnage = 0;}
CargoShip(int T) : Ship()
{ Tonnage = T;}
void setT(int T)
{ Tonnage = T;}
int getT() const
{ return Tonnage;}
virtual print()
{
cout << "The name of the ship is " << Name << " and it has a cargo capacity of " << Tonnage << " tons." << endl;
}
};
#endif CargoShip_H
|
ShipDemo.cpp
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
|
#include <iostream>
#include <iomanip>
#include "Cargo.h"
#include "Cruise.h"
#include "Ship.h"
using namespace std;
int main()
{
struct ship
{
int ship::setT;
int ship::setMP;
string ship::setN;
string ship::setY;
};
const int SHIPS = 3;
struct Ship *ship[SHIPS] =
{ new Ship ("Daytona", "1991"),
new CruiseShip (180, "Silverstone", "1999"),
new CargoShip (1800, "LeMan", "1962")
};
for (int i = 0; i < SHIPS; i ++)
{
cout << "The name of the ship is " << ship[i] -> getN();
cout << ship[i] -> print() << ship[i] -> getY() << endl;
return i;
}
cin.ignore();
cin.get();
return 0;
};
|