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 ==========

Hmm... are all the files in the same folder ?
Have you checked the project settings of visual studio for this particular project ?

Hi:

All files are in same folder.

As to the project settings, could you please elaborate? The project settings are still default (I am sure) as installed. I will look into this now.

Any suggestions (as to compiler\ project settings) are appreciated.

Thank-you for your reply.

Okay, I will just like you to try out one thing if possible by you.

Create a new console C++ project in VS 2005. Create three blank files in it: Main.cpp, Look.cpp and Look.h

Copy and paste the contents of the original files into these files, check to see if all the new files created are in the same folder and same view.

I cant tell you the specifics of VS 2005 since its currently not installed on my computer .

~s.o.s~:

TY for your reply.

I did as you suggested. All files are in the same project file.

I receive different errors now.

Compiling...
Look.cpp
 : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?

Main.cpp
 : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
Generating Code...

floodland - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I do not know what to make of this: I have never knowingly used #include "stdafx.h" before;when I make this new project, files named this (#include "stdafx.h" ) were added, but I simply got rid of them and created a new .h file (Look.h) and two .cpp files (Look.cpp, Main.cpp) then cut-and-pasted the code in question.

I do not know what the error refers to exactly; I looked it up and saw it to be a standard include library (?), so I just added it to the other "include" files on each .cpp file.

Please let me know what you think if you get the chance.

Thanks alot, ;)
Regards,

Arnold L.

Hi:

I made some adjustments to the compiler; I turned off the "precompiled headers" option (suggested on MSDN) and ran the build-- same, old error from before :

------ Build started: Project: floodland, Configuration: Debug Win32 ------
Compiling...
Look.cpp
Main.cpp
Generating Code...
Compiling manifest to resources...
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
floodland.exe : fatal error LNK1120: 2 unresolved externals

floodland - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Not sure what this means exactly. Will keep working it.;)

The reason you're getting those errors is because in your header file you defined Look::Look() and Look::~Look , and neglected to implement them in look.cpp.

The linker looks for the function code, can't find it, and spits out that error.

commented: ty +1

joeprogrammer:

TY for your reply. I appreciate you clarifying this. I am a bit confused at this point with classes in general; I have been working at this one area of the code for some time now and cannot get it to run. What you pointed out makes much better sense to me now. I am having trouble figuring out how to implement this in the Look.cpp file, though. The syntax is throwing me and all I keep getting is errors.

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;

}

Thanks,
Arnold L.

You have 2 options at this point:

You can choose to remove the constructor and destructor definitions from the class header. Classes are not required to have constructors/destructors.

You can add an implementation of these functions to the .cpp file. In this case, something like this would be all that you'd need:

// look.cpp
#include <iostream>
#include "Look.h"
using namespace std;

Look::Look() {
}

Look::~Look() {
}
// ...

joeprogrammer:

Thank-you for your reply. I tried your suggestion, adding

Look::Look() {
}
 
Look::~Look(){
}

It worked great. All error messages vanquished!

I really apprciate your help.

Arnold L.

The reason you're getting those errors is because in your header file you defined Look::Look() and Look::~Look , and neglected to implement them in look.cpp.

Maybe i am just going blind :eek:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.