需要帮助我的任务 [英] Need help with my assignment

查看:74
本文介绍了需要帮助我的任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误是

5 C:\ Users \User \Desktop \New proj\ASSIGN 1 \\\ main.cpp在main.cpp中包含的文件

32 C:\ Users \User \Desktop \New proj\ASSIGN 1 \ MissMlan.h expect`;'before'('token

C:\ Users\User\Desktop\New proj\ASSIGN 1\main.cpp在构造函数`MissionPlan :: MissionPlan()'中:

58 C:\ Users \ User \ Desktop \New proj\ASSIGN 1 \\\ main.cpp没有足够的上下文信息来确定类型

114 C:\ Users \ User.\\Desktop\New proj\ASSIGN 1 \ main.cpp没有匹配函数来调用`getline(std :: istream&,< unknown type =>)'



///// ////////////////////////////////////////////////// /////////////////////////////

代码



LocationData.h

THE ERRORS ARE
5 C:\Users\User\Desktop\New proj\ASSIGN 1\main.cpp In file included from main.cpp
32 C:\Users\User\Desktop\New proj\ASSIGN 1\MissionPlan.h expected `;' before '(' token
C:\Users\User\Desktop\New proj\ASSIGN 1\main.cpp In constructor `MissionPlan::MissionPlan()':
58 C:\Users\User\Desktop\New proj\ASSIGN 1\main.cpp insufficient contextual information to determine type
114 C:\Users\User\Desktop\New proj\ASSIGN 1\main.cpp no matching function for call to `getline(std::istream&, <unknown type="">)'

////////////////////////////////////////////////////////////////////////////////////
THE CODES

LocationData.h

#include <iostream>

#include <string>

#include <math.h>



using namespace std;


class LocationData
{
private:
string sunType;
int noOfEarthLikePlanets;
int noOfEarthLikeMoons;
float aveParticulateDensity;
float avePlasmaDensity;
float computeCivIndex;

public:
LocationData();
LocationData(string, int, int, float, float);
string getsunType();
void setsunType(string new_sunType);
int getnoOfEarthLikePlanets();
void setnoOfEarthLikePlanets(int );
int getnoOfEarthLikeMoons();
void setnoOfEarthLikeMoons(int );
float getaveParticulateDensity();
void setaveParticulateDensity(float );
float getavePlasmaDensity();
void setavePlasmaDensity(float );
float getcomputeCivicIndex();
void setcomputeCivicIndex(float );
void toString();
float civIndex(string , int , int , float , float );


};

LocationData.cpp

LocationData.cpp

#include <iostream>
#include <string>
#include "LocationData.h"

using namespace std;

LocationData::LocationData()
{
sunType = "";
noOfEarthLikePlanets = 0;
noOfEarthLikeMoons = 0;
aveParticulateDensity = 0;
avePlasmaDensity = 0;
}

LocationData::LocationData(string newsunType, int newnoOfEarthLikePlanets, int newnoOfEarthLikeMoons, float newaveParticulateDensity, float newavePlasmaDensity)
{
sunType= newsunType;
noOfEarthLikePlanets = newnoOfEarthLikePlanets;
noOfEarthLikeMoons = newnoOfEarthLikeMoons;
aveParticulateDensity = newaveParticulateDensity;
avePlasmaDensity = newavePlasmaDensity;
}

string LocationData::getsunType()
{
return sunType;
}

void LocationData::setsunType(string new_sunType)
{
sunType = new_sunType;
}

int LocationData::getnoOfEarthLikePlanets()
{
return noOfEarthLikePlanets;
}

void LocationData::setnoOfEarthLikePlanets(int new_noOfEarthLikePlanets)
{
noOfEarthLikePlanets = new_noOfEarthLikePlanets;
}

int LocationData::getnoOfEarthLikeMoons()
{
return noOfEarthLikeMoons;
}

void LocationData::setnoOfEarthLikeMoons(int new_noOfEarthLikeMoons)
{
noOfEarthLikeMoons = new_noOfEarthLikeMoons;

}

float LocationData::getaveParticulateDensity()
{
return aveParticulateDensity;
}

void LocationData::setaveParticulateDensity(float new_aveParticulateDensity)
{
aveParticulateDensity = new_aveParticulateDensity;
}

float LocationData::getavePlasmaDensity()
{
return avePlasmaDensity;
}

void LocationData::setavePlasmaDensity(float new_avePlasmaDensity)
{
avePlasmaDensity = new_avePlasmaDensity;
}

void LocationData::toString()
{
cout<<"The suntype is "<<sunType<<endl<<
"The no of Earth-like Planets is "<<noOfEarthLikePlanets<<endl<<
"The no of Earth-like Moons is "<<noOfEarthLikeMoons<<endl<<
"The average Particulate Density is "<<aveParticulateDensity<<endl<<
"The average Plasma Density is "<<avePlasmaDensity<<endl;
}

float LocationData::computeCivIndex(string sunType, int noOfEarthLikePlanets, int noOfEarthLikeMoons, float aveParticulateDensity, float avePlasmaDensity)
{
float sunTypePercent;
float civIndex;
if (sunType == "O" || sunType == "o") sunTypePercent = 30;
if (sunType == "B" || sunType == "b") sunTypePercent = 45;
if (sunType == "A" || sunType == "a") sunTypePercent = 60;
if (sunType == "F" || sunType == "f") sunTypePercent = 75;
if (sunType == "G" || sunType == "g") sunTypePercent = 90;
if (sunType == "K" || sunType == "k") sunTypePercent = 80;
if (sunType == "M" || sunType == "m") sunTypePercent = 70;

civIndex = ((sunTypePercent / 100) - (aveParticulateDensity + avePlasmaDensity) / 200) * (noOfEarthLikePlanets + noOfEarthLikeMoons);

return civIndex;
}

MissionPlan.h

MissionPlan.h

#include <iostream>
#include <string>
#include "PointTwoD.h"

using namespace std;
class MissionPlan

{

public:

MissionPlan();
float computeCivIndex(string, int, int, float, float);
void showDistance();
void mainMenu();
void showEntry();
int x;
float ci;

int y;

int counter;
float distance;

string sunType;

int noOfEarthLikePlanets, noOfEarthLikeMoons;

float aveParticulateDensity, avePlasmaDensity;

PointTwoD dataStore[100];

PointTwoD getData;
float computeCivIndex(ci);
void computeCivIndex(float);

//cout<<"Please select your choice :";

//cin>>choice;

};

MissionPlan.cpp

MissionPlan.cpp

#include <iostream>
#include <string>
#include "MissionPlan.h"


using namespace std;
float MissionPlan::computeCivIndex(string sunType, int noOfEarthLikePlanets,int noOfEarthLikeMoons, float aveParticulateDensity, float avePlasmaDensity)

{


if(sunType == "Type O")

ci = (30/100)-(aveParticulateDensity + avePlasmaDensity)/200*(noOfEarthLikePlanet + noOfEarthLikeMoons);

else if(sunType == "Type B")

ci = ((45/100)-(aveParticulateDensity + avePlasmaDensity)/200)*(noOfEarthLikePlanets + noOfEarthLikeMoons);

else if(sunType == "Type A"

ci = ((60/100)-(aveParticulateDensity + avePlasmaDensity)/200)*(noOfEarthLikePlanets + noOfEarthLikeMoons);

else if(sunType == "Type F")

ci = ((75/100)-(aveParticulateDensity + avePlasmaDensity)/200)*(noOfEarthLikePlanets + noOfEarthLikeMoons)

else if(sunType == "Type G")

ci = ((90/100)-(aveParticulateDensity + avePlasmaDensity)/200)*(noOfEarthLikePlanets + noOfEarthLikeMoons);

else if(sunType == "Type K")

ci = ((80/100)-(aveParticulateDensity + avePlasmaDensity)/200)*(noOfEarthLikePlanets + noOfEarthLikeMoons);

else if(sunType == "Type M")

ci = ((70/100)-(aveParticulateDensity + avePlasmaDensity)/200)*(noOfEarthLikePlanets + noOfEarthLikeMoons);

else

cout<<"Error! No such type!!"<<endl;

return computeCivIndex;
}
void MissionPlan::showDistance()
{
distance = sqrt(((x*x) + (y*y))*100);

cout << "Total (approx) travel distance = ";
cout << distance <<" million km"<< endl;
}



PointTwoD.h


PointTwoD.h

#include <iostream>
#include <string>
#include "LocationData.h"

using namespace std;

class PointTwoD
{
private:
int x;
int y;
LocationData locationData;


public:
float civIndex;
PointTwoD();
PointTwoD(int new_x, int new_y, LocationData new_locationData, float new_civIndex);
int getx();
void setx(int new_x);
int gety();
void sety(int new_y);
string getsunType();
void setsunType(string new_sunType);
int getnoOfEarthLikePlanets();
void setnoOfEarthLikePlanets(int new_noOfEarthLikePlanets);
int getnoOfEarthLikeMoons();
void setnoOfEarthLikeMoons(int new_noOfEarthLikeMoons);
float getaveParticulateDensity();
void setaveParticulateDensity(float new_aveParticulateDensity);
float getavePlasmaDensity();
void setavePlasmaDensity(float new_aveParticulateDensity);
//float getcomputeCivicIndex();
//void setcomputeCivicIndex(string, int, int, float, float);
LocationData getlocationData();
void setlocationData(LocationData new_locationData);
float getcivIndex(void);
void setxy(int new_x,int new_y);
void setcivIndex(float new_civIndex);
void toString();
//static float computeCivicIndex;


};

PointTwoD.cpp

PointTwoD.cpp

#include <iostream>
#include <string>
#include "PointTwoD.h"

using namespace std;
PointTwoD::PointTwoD()
{
x = 0;
y = 0;
LocationData locationData();
civIndex = 0;
}

PointTwoD::PointTwoD(int new_x, int new_y, LocationData new_locationData, float new_civIndex)
{
x = new_x;
y = new_y;
locationData = new_locationData;
civIndex = new_civIndex;
}

int PointTwoD::getx()
{
return x;
}

void PointTwoD::setx(int new_x)
{
x = new_x;
}

int PointTwoD::gety()
{
return y;
}

void PointTwoD::sety(int new_y)
{
y = new_y;
}

void PointTwoD::setxy(int new_x,int new_y)
{
x=new_x;
y=new_y;
}

LocationData PointTwoD::getlocationData()
{
return locationData;
}

void PointTwoD::setlocationData(LocationData new_locationData)
{
locationData = new_locationData;
}

float PointTwoD::getcivIndex()
{
return civIndex;
}

void PointTwoD::setcivIndex(float new_civIndex)
{
civIndex = new_civIndex;
}

void PointTwoD::toString()
{
cout<<"Civ Idx : "<<civIndex<<" at sector ("<<x<<","<<y<<")"<<endl;

}





[edit]已添加代码块 - OriginalGriff [/ edit]



[edit]Code blocks added - OriginalGriff[/edit]

推荐答案

修复你的MissionPlan.h。

你调用执行代码而不是在类的功能中。

你不能直接在类体中调用可执行代码,你必须在函数中这样做。

另见我对你的问题的评论。

干杯
Andi
Fix your MissionPlan.h.
You call executing code without being in a function of the class.
You cannot call executable code directly in the class body, you have to be in a function to do so.
See also my comment to your question.
Cheers
Andi


这篇关于需要帮助我的任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆