Hi i am currently doing a program for my assignment at university level. I have met with the following problems. The program takes in values from a main class(main.cpp) then transfers the values via a get method from the locationData class(location.cpp). The problem is i declared locationData as locationData data in main.cpp and tried to get a value using a getmethod which resides in the locationData class. However, when i tried to compile it it gives me an error that says in function int main(), no match for operator cin>>data.locationData::getSunType
void showProgram()
{
cout<<"Welcome to Mission Plan program!"<<endl<<
"1)Input statistical data."<<endl<<
"2)Compute civ. index value (for all records)"<<endl<<
"3)Print top 5 exploration destinations."<<endl<<
"4) Print total travel distance."<<endl;
}
int main()
{
locationData data;
string sunType;
int xCord,yCord,noOfEarthPlanet,noOfEarthMoon;
int choice;
float aveParticulateDensity;
float avePlasmaDensity;
showProgram();
cout<<"Please select your choice :";
cin>>choice;
switch(choice)
{
case 1 : cout<<"Input statistical data"<<endl;
cout<<"Please enter x-cordinate:";
cin>>xCord;
cout<<"Please enter y-cordinate:";
cin>>yCord;
cout<<"Please enter sun type: TYPE:";
cin>>data.getSunType(sunType);
cout<<"Please enter no. of earth-like planets:";
cin>>noOfEarthPlanet;
cout<<"Please enter no. of earth-like moons:";
cin>>noOfEarthMoon;
cout<<"Please enter ave. particulate density (%-tage):";
cin>>aveParticulateDensity;
cout<<"Please enter ave. plasma density (%-tage):";
cin>>avePlasmaDensity;
cout<<"Record succesfully stored. Going back to main menu."<<endl;
break;
default: cout<<"Invalid choice, please re-enter your choice."<<endl;
}
return 0;
}
locationData.cpp
#include<iostream>
#include<string>
using namespace std;
class locationData
{
private:
string sunType;
int noOfEarthLikePlanets;
int noOfEarthLikeMoons;
float aveParticulateDensity;
float avePlasmaDensity;
Hi hutch i tried that too. But it returns another error.
tmp/ccLawY4W.o: In function `locationData::getSunType(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
locationData.cpp:(.text+0x0): multiple definition of `locationData::getSunType(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
You shouldn't include .cpp files. Now you are including the definition of getSunType in multiple files so the function is being defined multiple times so that is probably why you get the error. Instead you should create a header file (locationData.h) that you include (#include "locationData.h"). The header file should contain the class definition, while the .cpp file contains all the function definitions of the class.