Hi,
I am working on a fairly simple project (it will grow more in time as planned) but I am stuck in a spot which I cannot solve yet.
The operation of this prog at this point is:
- Start. Ask user for input choice (only 1 choice available at this point)
- Cin will take user to another screen (another file, Look.cpp) This file will run and request more input.
- This input will run
- End.
My problem is how to "link" Main.cpp and the cin input to Look.cpp where the action is located, that is, more input is requested. This will be done using classes.
I consider the action of going to Look.cpp a "function" as declared in Look.h. Maybe this action is not a true function; it does no mathematical operation-- and does it return anything? No, it is void.
I feel very close to solving this but errors keep getting thrown. Perhaps it is just my syntax in the use of objects, referencing, etc?
Any help is greatly appreciated-- thank you in advance.
Arnold L. :)
Look.h
class Look {
public:
float shipPos ;
float satPos;
float interior;
void printShipPos(); // new function declaration
Look();
~Look();
};
Look.cpp
#include <iostream>
#include "Look.h"
using namespace std;
void Look::printShipPos() //.h function set here, refers to class
// Look via "::"
{
cin >> shipPos; // this shipPos is the Look class member variable
if (shipPos <= 3.80) {
std::cout << "French Polynesia [Out of Transmission Range]"<< endl;
}
else if (shipPos <= 7.60) {
std::cout << "Maui, Hawaii [Out of Transmission Range]"<< endl;
}
else if (shipPos <= 11.40) {
std::cout << "Pacific Ocean (open waters) [Out of Transmission Range] 4320 miles from Tampa, Florida"<< endl;
}
else if ((shipPos >= 15.20) && (shipPos < 19.00)) {
std::cout << "Pacific Ocean (open waters) [In Transmission Range] 3240 miles from Tampa, Florida"<< endl;
}
else if ((shipPos >= 19.00) && (shipPos < 22.80)){
std::cout << "La Paz, Baja, Mexico [In Transmission Range]"<< endl;
}
else if ((shipPos >= 22.80) && (shipPos < 26.60)){
std::cout << "Gulf of Mexico [In Transmission Range]"<< endl;
}
else if ((shipPos >= 26.60) && (shipPos < 30.40)){
std::cout << "Tampa, Florida [In Transmission Range]"<< endl;
}
else if ((shipPos >= 30.40) && (shipPos < 34.20)){
std::cout << "Atlantic Ocean (open waters) [In Transmission Range] 4320 miles from Lisbon, Portugal"<< endl;
}
else if ((shipPos >= 34.20) && (shipPos < 38.00)){
std::cout << "Atlantic Ocean (open waters) [In Transmission Range] 3240 miles from Lisbon, Portugal"<< endl;
}
else if (shipPos <= 38.00) {
std::cout << "Atlantic Ocean (open waters) [In Transmission Range] 2160 miles from Lisbon, Portugal"<< endl;
}
else if (shipPos <= 41.80) {
std::cout << "Canary Islands [Out of Transmission Range]"<< endl;
}
else if (shipPos <= 45.60) {
std::cout << "Lisbon, Portugal [Out of Transmission Range]"<< endl;
}
else if (shipPos <= 49.40) {
std::cout << "Tripoli, Libya [Out of Transmission Range]"<< endl;
}
else if (shipPos <= 53.20) {
std::cout << "Baghdad, Iraq [Out of Transmission Range]"<< endl;
}
else if (shipPos <= 57.00) {
std::cout << "Eastern Iran [Out of Transmission Range]"<< endl;
}
else if (shipPos <= 60.80) {
std::cout << "Central Tajikistan [Out of Transmission Range]"<< endl;
}
else if (shipPos <= 64.60) {
std::cout << "Kathmandu, Nepal [Out of Transmission Range]"<< endl;
}
else if (shipPos <= 68.40) {
std::cout << "Hanoi, Vietnam [Out of Transmission Range]"<< endl;
}
else if (shipPos <= 72.20) {
std::cout << "Hong Kong, China [Out of Transmission Range]"<< endl;
}
else if (shipPos <= 76.00) {
std::cout << "Pacific (open waters) [Out of Transmission Range] 5400 miles from French Polynesia"<< endl;
}
else if (shipPos <= 79.80) {
std::cout << "Pacific (open waters) [Out of Transmission Range] 4320 miles from French Polynesia"<< endl;
}
else if (shipPos <= 83.60) {
std::cout << "Pacific (open waters) [Out of Transmission Range] 3240 miles from French Polynesia"<< endl;
}
else if (shipPos <= 87.40) {
std::cout << "Pacific (open waters) [Out of Transmission Range] 2160 miles from French Polynesia"<< endl;
}
else{
std::cout << "Pacific (open waters) [Out of Transmission Range] 1080 miles from French Polynesia"<< endl;
}
return;
}
//-----------------------------------------------
//float satPos; //function 2 - view of 5 satellites
//{
//cin >> satPos;
//float interior; //function 3 - view of station interior
//{
//cin >> interior;
Main.cpp
#include <iostream>
#include "Look.h"
using namespace std;
int choice;
int main()
{
std::cout << "________________________________"<< endl;
std::cout << ""<< endl;
std::cout << "Welcome to Platform XYZ-- Please Enter a Number:"<< endl;
std::cout << ""<< endl;
std::cout << "[1]Check Location for Transmission to Base"<< endl;
std::cout << "[2]Stub"<< endl;
std::cout << ""<< endl;
std::cout << "________________________________"<< endl;
cin >> choice;
Look look1; //** ERROR?
if(choice == 1){
look1.printShipPos(); //** ERROR?
}
else {
std::cout << "OTHER! chosen (stub)"<< endl;
}
system("PAUSE");
return 0;
}
Error Message (VC++ Express 2005)
Compiling...
main.cpp
Linking...
main.obj : error LNK2019: unresolved external symbol "public: __thiscall Look::~Look(void)" (??1Look@@QAE@XZ) referenced in function _main
main.obj : error LNK2019: unresolved external symbol "public: __thiscall Look::Look(void)" (??0Look@@QAE@XZ) referenced in function _main
C:\Documents and Settings\RockStar\Desktop\Space_Station\spaceStation\Debug\spaceStation.exe : fatal error LNK1120: 2 unresolved externals
Build log was saved at "file://c:\Documents and Settings\RockStar\Desktop\Space_Station\spaceStation\spaceStation\Debug\BuildLog.htm"
spaceStation - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========