C++ Classes: Use, Misuse...Confusion.

This is a discussion on C++ Classes: Use, Misuse...Confusion. within the C++ Programming forums, part of the General Programming Boards category; I am attempting to better understand C++ Classes. I am working on a simple program called "spacestation", a space simulator ...

  1. #1
    Registered User Snorpy_Py's Avatar
    Join Date
    Oct 2006
    Posts
    3

    Question C++ Classes: Use, Misuse...Confusion.

    I am attempting to better understand C++ Classes. I am working on a simple program called "spacestation", a space simulator of sorts that will hopefully allow me to explore and understand Classes, their use(s) and their potential.

    I am very lost at this point and have been researching Classes and Functions for the past week and, although I have learned alot in general about coding I have not found a solution for my problem. I simply wish to run the code (Main)at compile- Allow a user to select a choice from the screen (in this case the only enabled choice is "1")- Upon choosing "1" (and this is where I am lost) a cpp file titled "viewEarth" is activated (called) and a "function" run.

    I am lost when it comes to how to link the action from Main (choice "1" by the user) to viewEarth.cpp (which should, in theory, bring up something on the screen from that file (at this point viewEarth.cpp is not fully functional, which is O.K.-- I just need to figure out the problem with Classes, Functions, Calls. I am lost in the syntax. Am I lost in the syntax? The code is not pretty, but is posted below in rough form. This is one of many versions I have written, the most current one. I feel the more I work it without the proper understanding of Classes, etc, the deeper into confusion I descend.

    Any help would be so appreciated at this point-- any shove in the right direction and any positive critiques are very welcome. Thank-you in advance.
    (Code listed below is C++ and built on in Visual C++ Express 2005)



    viewEarth.H
    Code:
    #include <iostream>
    
    
    using namespace std;
    
    class Message
    {
    public:
    	
    void See();
    
    
    private:
    float shipPos;	
    };
    main.cpp
    Code:
    #include <iostream>
    #include "viewEarth.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;
    
    	if (choice == 1) {
    		Request1.See();
    		//class Message;
    		
    		//std::cout <<"Check Position"<< endl;
    	}
    	else {
    		std::cout << "OTHER! chosen (stub)"<< endl;
    	}
    	
    	
    	system("PAUSE");
    
    return 0;
    }
    Code:
    #include <iostream>
    #include "viewEarth.h"
    
    using namespace std;
    
    void See()
    {
    cin >> shipPos;
                
    			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;  
    }
    			
    			system("PAUSE");
    
    }
    Compiler Build Output
    Code:
    ------ Build started: Project: spaceStation, Configuration: Debug Win32 ------
    Compiling...
    viewEarth.cpp
    .\viewEarth.cpp(10) : error C2065: 'shipPos' : undeclared identifier
    main.cpp
    .\main.cpp(24) : error C2065: 'Request1' : undeclared identifier
    .\main.cpp(24) : error C2228: left of '.See' must have class/struct/union
            type is ''unknown-type''
    Generating Code...
    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 ==========

  2. #2
    Registered User Snorpy_Py's Avatar
    Join Date
    Oct 2006
    Posts
    3
    Also, my above post is formatted most bizarre-- I am not sure why. Sorry for the forced screen scroll.

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Are you sorry for the bolding of the entire text, too?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,340
    >> error C2065: 'shipPos' : undeclared identifier
    >> void See()
    You are defining the See member function of the Message class, so you need to tell the compiler that the function you are implementing belongs to Message. Otherwise it won't know that when you refer to shipPos you are referring to the shipPos that is part of the class.

    >> error C2065: 'Request1' : undeclared identifier
    >> Request1.See();
    This time you must tell the compiler that Request1 is a variable whose type is Message, otherwise it has no idea what Request1 is when you try to use it.

  5. #5
    Registered User Snorpy_Py's Avatar
    Join Date
    Oct 2006
    Posts
    3

    ?

    Quote Originally Posted by CornedBee
    Are you sorry for the bolding of the entire text, too?

    Please forgive me for choosing a standard formatting option--LOL

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ confusion
    By Eirik in forum Windows Programming
    Replies: 14
    Last Post: 04-29-2009, 01:54 PM
  2. Classes - Confusion
    By Kane in forum C++ Programming
    Replies: 8
    Last Post: 01-27-2005, 09:55 AM
  3. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-23-2004, 11:22 PM
  4. classes and oop confusion
    By ssjnamek in forum C++ Programming
    Replies: 7
    Last Post: 11-27-2003, 09:08 AM
  5. classes confusion
    By Trublu in forum C++ Programming
    Replies: 1
    Last Post: 06-07-2003, 01:19 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21