Thread: Just need your quick advice/opinion

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    29

    Arrow Just need your quick advice/opinion

    I have to design and inplement a project that makes use of classes, arrays, input files, functions etc.. I need an original unique ideas. I was think maybe street directions to my campus, calculus calculations, or sports statistics, but these seem like someone else might do the same...Any ideas from you guys?

  2. #2
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    >directions to my campus


    that sounds like a good idea. you could be even more general and have an input file with places and streets (along with the street distance, basically nodes with adjacency lists) then given a starting and ending point (standard IO) you could use shortest path algorithms to calculate the fastest path to take to get to these places. then output the streets to take.

    that would make use of "classes, arrays, input files, functions etc"
    im not sure what level you are programming at, if this is too complicated, you could make it less general (ie. directions to your campus). if this idea is too simple, you could make it more complex (ie, include actual neighborhoods, maybe major city routes)

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    29

    Arrow Perspective

    Hey thanks for the help, I am in a 1st semester C++ class here at the Colorado School of Mines, I dont think I have used StandardIO or Path algorithms or nodes. Do you think I could just do routes to different buildings, with my knowladge base or should I try to use getting from major streets to the campus?

  4. #4
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    standard IO : things like cin and cout.

    >Do you think I could just do routes to different buildings

    that sounds like good idea. althought you still need a way to determine the best way from one building to another. you could just store all the info in the input file (probably a good idea if you havent studied shortest path algorithms).

  5. #5
    Registered User
    Join Date
    Feb 2003
    Posts
    29

    Lightbulb Perspective

    Oh sorry I was confused about the way you wrote stadard IO. So what your saying is I could store the different routes in the input file, and create a class of building, and give it characeristics like building is hill hall, math department, at this location? I guess I am just questioning how it all ties in together is this what you were thinking?

  6. #6
    Registered User
    Join Date
    Feb 2003
    Posts
    29

    Thumbs up perspective

    Thanks alot for your help I will try to think about it some more and possibly e-mail you if thats ok with you? Any other ideas, or suggestions would be appreciated. Thanks again!!

    [email protected]

  7. #7
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    it could be difficult to store all the fastest routes depending on how many buildings you plan on incuding. You'll need to have the path between every possible 2 buildings. heres what im suggesting (*note there is a better solution using shortest path algorithms)

    Code:
    // pseudo code
    class Route
    {
         locationA;
         locationB;
         path;
    }
    
    int main()
    {
         cout << "Enter Start place" ;
          cin ....  // get start place and destination
    
          arrayOfRoutes = readInputFileOfRoutes;
    
          for( looping stuff)
          {
               if( (arrayOfRoutes.locationA == startPlace && arrayOfRoutes.locationB == endPlace) || (arrayOfRoutes.locationB == startPlace && arrayOfRoutes.locationA == endPlace))
     
                       cout << arrayOfRoutes.path ;
          }
    }
    i hope this helps and doesnt give away too much. good luck

  8. #8
    Registered User
    Join Date
    Feb 2003
    Posts
    29

    Arrow Perspective

    Perspective


    After thinking this out for awhile and reading this pseudo code you gave me It has been very difficult for me to implement the program. In this class route that you gave me what types are all the variables supposed to be? locationB is of type what? and path is of type what? How do I get each direction from my txt file into this variable of path? I have all my routes from one building to another stored in a .txt file. What are my public and private variables here? Shouldnt I have a class of maybe buildings instead, with a cstring for the routes, and a get_route fxn also in this class? I am struggleing so much getting this done and I barely know where to begin, I think your algorithm is probably more simple then what I am thinking of I just need some more pointers. Thanks!

    Joe

  9. #9
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    the types are up to you. here is an example..

    Code:
    // in routes.h (or whatever)
    
    class Routes
    {
         // you can use c-strings or whatever you like using
         string locA, locB, route;  
    
    public:
    
         ......
    
          void setLocationOne(string location);
          void setLocationTwo(string  location);
          void setRoute(string route);
    
          string  getLocationOne();
          string  getLocationTwo();
          string  getRoute();
    
    };
    
    // in Routes.cpp -------------------------------------------------------------
    
    void Routes::setLocationOne(string  location)
    {
             locA = location;
    }
    
    //.... and so on
    
    string Routes::getLocationOne()
    {
         return locA;
    }
    
    //...... and so on
    
    
    // data.txt ----------------------------------------------------------------------
    
    math building
    science building
    The best route between..... is to go this way ......
    
    math building
    study hall
    the route from......
    
    science building
    study hall
    go this way....
    
    // initiallizing in main code. (pseudo-code) --------------------------------
    
    Routes r[number of records];    // actuall number or else dynamic allocation
    
    for(index = 0; .... number of records)
    {
          r[index].setLocationOne(cin.getFirstLine());
          r[index].setLocationTwo(cin.getSecondLine());
          r[index].setRoute(cin.getThirdLine());
    }
    
    // out put dialogue, get users desired locations.
    
    string userLoc1, userLoc2;
    
    for( number of records)
    {
        // note the '==' is just pseudo for comparing, actually use compare functions (ie. strcmp() )
        if ( (userLoc1 ==  r[index].getLocationOne() && userLoc2 == 
             r[index].getLocationTwo() ) || (the oppisites match ) )
        { 
                     cout << "The best route is " << r[index].getRoute();
                      break;
         }
    }
    i hope that helps, just lemmie know if you have anymore questions.... perhaps post some code.
    Last edited by Perspective; 04-28-2003 at 06:14 PM.

  10. #10
    Registered User
    Join Date
    Feb 2003
    Posts
    29

    peerspective

    In the driver file if I had 12 different directions, so there are 36 lines in my txt file. is this how I would write the code for the for loop? How do I tell the program to get to other buildings and other directions? I am also having trouble figureing out where my input file comes into play? I am also getting a compiler message that string is not defined any ideas? Here is what I have so far for the driver portion.

    Code:
    #include <iostream.h>
    #include <string.h>
    #include <fstream.h>
    #include <stdlib.h>
    #include "building.h"
    
    
    void main()
    {
    
      building b[12];
      string userLocA;
      string userLocB;
      ifstream input_file;
    
      input_file.open("paths.txt");
      if(input_file.fail())
        {
          cout <<"Input file could not be opened.\n";
          exit(1);
        }
    
      for(int index=0; index<12; index++)
        {
          b[0].intLocationOne(cin.getFirstLine());
          b[1].intLocationTwo(cin.getSecondLine());
          b[2].setPath(cin.getThirdLine());
          b[3].intLocationOne(cin.getFithLine());
          b[4].intLocationTwo(cin.getSixthLine());
          b[5].setPath(cin.getSeventhLine());
    etc...
        }
      cout <<"\nCAMPUS DIRECTIONS!\n";
      cout <<"Here are your building choices:\n";
      cout <<"Student Center, Weaver, CTLM, and Coolbaugh\n";
      cout <<"Where are you now?";
      cin >> userLocA;
      cout <<"Where do you want to go?";
      cin >> userLocB;
      
      for (int 12)
        {
          if ((strcmp(userLocA, r[index].getLocation1()))&&(strcmp(userLocB, r[index.getLocation2()))))
    	{
    	  cout << "Here are your directions:" << b[index].getPath();
    	  break;
    	}
        }
      
      
    
    }

  11. #11
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    >
    for(int index=0; index<12; index++)
    {
    b[0].intLocationOne(cin.getFirstLine());
    b[1].intLocationTwo(cin.getSecondLine());
    b[2].setPath(cin.getThirdLine());
    b[3].intLocationOne(cin.getFithLine());
    b[4].intLocationTwo(cin.getSixthLine());
    b[5].setPath(cin.getSeventhLine());
    etc...
    }
    <


    you want to let the for loop do the indexing here, maybe this is more clear

    Code:
    for(int index=0; index< 12; index++)
        {
          b[index].intLocationOne(input_file.getFullLineFromTXT());
          b[index].intLocationTwo(input_file.getFullLineFromTXT());
          b[index].setPath(input_file.getFullLineFromTXT());
    
        }
    this will put the first line in your file as locA of the first building in b. the second line will be locB of the first building in b. the third line will be the path of the first building in b.

    the fourth line will be locA of the second building in b. the fifth line will be locB of the second building in b. the sixth line will be the path of the second building in b.... etc.... etc....


    also try adding: " using namespace std; " to the top of your file and you dont need the '.h' in your include statements.

  12. #12
    Registered User
    Join Date
    Feb 2003
    Posts
    29

    Arrow Perspective

    Thanks for your help with my program, it looks like I have an older compiler and it doest have the string type included in its libraries.. So I will have to change everything to char location1[] etc... That will probably take me awhile since my program will run slightly differently, let me know if you have any suggestions.

  13. #13
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    you should be able to use string if you have this at the top:

    #include <iostream>
    using namespace std;

    otherwise be sure to use strcpy() instead of just = when doing an assignment. let me know how it goes!

  14. #14
    Registered User
    Join Date
    Feb 2003
    Posts
    29

    Arrow perspective

    Here are all my compnents to my program, the driver file, the header file for building and the definitions for building. I am getting seven compiler errors for the building.cpp the definitions, it says it wants semilcolons after all braces, and it also say that the return expression differs from the fxn return type when I try to return locA; or locB etc... any ideas? Also is the second for loop in my driver ok?

    header
    Code:
    #include <iostream.h>
    #include <string.h>
    #include <stdlib.h>
    
    class building
    {
    
     public:
      void intLocationOne(char location1[10]);
      void intLocationTwo(char location2[10]);
      void setPath(char route[120]);
    
      char getLocationOne();
      char getLocationTwo();
      char getPath();
    
     private:
    
      char locA[10], locB[10], path[10];
    
    }

  15. #15
    Registered User
    Join Date
    Feb 2003
    Posts
    29

    Arrow code

    definitions building.cpp

    Code:
    #include <string.h>
    #include <stdlib.h>
    #include <iostream.h>
    #include "building.h"
    
    void building::intLocationOne(char location1[10])
    {
     strcpy(locA, location1) 
    
    }
    
    void building::intLocationTwo(char location2[10])
    {
      strcpy(locB, location2) 
    
    }
    
    void building::setPath(char route[10])
    {
      strcpy(path, route)
    }
    
    char building::getLocationOne()
    {
      return locA;
    }
    
    char building::getLocationTwo()
    {
      return locB;
    }
    
    char building::getPath()
    {
      return path;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strcmp returning 1...
    By Axel in forum C Programming
    Replies: 12
    Last Post: 09-08-2006, 07:48 PM
  2. Do you know...
    By davejigsaw in forum C++ Programming
    Replies: 1
    Last Post: 05-10-2005, 10:33 AM
  3. recursive quick sort - stack overflow
    By Micko in forum C Programming
    Replies: 9
    Last Post: 01-01-2005, 05:51 PM
  4. Questions on basic Quick Sort
    By Weng in forum C++ Programming
    Replies: 4
    Last Post: 12-16-2003, 10:06 AM
  5. Replies: 0
    Last Post: 04-30-2002, 07:24 PM