8 Replies - 1259 Views - Last Post: 27 September 2013 - 08:26 AM Rate Topic: -----

#1 VuKid   User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 57
  • Joined: 27-September 13

Read cities from file

Posted 27 September 2013 - 07:59 AM

Write and test a C++ program to perform the following:
 Read the contents of the .csv file containing city names, latitudes, and longitudes into a set of parallel arrays.
 Repeat the following until the user enters “Quit”.
o Ask the user to pick a city, by name, from the list.



How would I do the picking a city based on user input?
Is This A Good Question/Topic? 0
  • +

Replies To: Read cities from file

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 16479
  • View blog
  • Posts: 65,313
  • Joined: 12-June 08

Re: Read cities from file

Posted 27 September 2013 - 08:02 AM

Read in the cities from your file.. store them in a collection (list, array, dictionary, etc).. display the options on the screen with some sort of numerical value.. ask the user to type a number to correspond to a city.
Was This Post Helpful? 0
  • +
  • -

#3 VuKid   User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 57
  • Joined: 27-September 13

Re: Read cities from file

Posted 27 September 2013 - 08:04 AM

Can you give me an example code? I know it's a for loop but not sure on how to do it. I have them stored in a struct from the cvs file.
struct location {
    string city;
    string country;
    double latitude;
    double longitude;
};


How do i manipulate them?

This post has been edited by jimblumberg: 27 September 2013 - 08:09 AM
Reason for edit:: Added missing code tags.

Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 16479
  • View blog
  • Posts: 65,313
  • Joined: 12-June 08

Re: Read cities from file

Posted 27 September 2013 - 08:10 AM

Example code of what part? Do you not know how to load a file? Do you not know about collections? Do you not know about display something to a console?
Was This Post Helpful? 0
  • +
  • -

#5 VuKid   User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 57
  • Joined: 27-September 13

Re: Read cities from file

Posted 27 September 2013 - 08:15 AM

View Postmodi123_1, on 27 September 2013 - 08:10 AM, said:

Example code of what part? Do you not know how to load a file? Do you not know about collections? Do you not know about display something to a console?



I am new, I'm not sure on how to do that. examples would help please.
Was This Post Helpful? 0
  • +
  • -

#6 jimblumberg   User is offline

  • member icon

Reputation: 5916
  • View blog
  • Posts: 17,932
  • Joined: 25-December 09

Re: Read cities from file

Posted 27 September 2013 - 08:16 AM

In other words you need to show us what you've tried. Then we can help you get on the right path.


Jim
Was This Post Helpful? 0
  • +
  • -

#7 VuKid   User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 57
  • Joined: 27-September 13

Re: Read cities from file

Posted 27 September 2013 - 08:20 AM

#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <stdio.h>
#include <fstream>
using namespace std;

int main()
{
struct location {
    string city;
    string country;
    double latitude;
    double longitude;
};

ifstream inFile; //input file stream variable    
inFile.open("file.cvs"); //opens the input file




This is what i have so far, I dont' think it is correct in what i am trying to get at,

Write and test a C++ program to perform the following:
 Read the contents of the .csv file containing city names, latitudes, and longitudes into a set of parallel arrays.
 Repeat the following until the user enters “Quit”.
o Ask the user to pick a city, by name, from the list.

This post has been edited by jimblumberg: 27 September 2013 - 08:21 AM
Reason for edit:: Added missing code tags.

Was This Post Helpful? 0
  • +
  • -

#8 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6968
  • View blog
  • Posts: 31,958
  • Joined: 10-May 07

Re: Read cities from file

Posted 27 September 2013 - 08:21 AM

** Renamed title to be more descriptive **
Was This Post Helpful? 0
  • +
  • -

#9 jimblumberg   User is offline

  • member icon

Reputation: 5916
  • View blog
  • Posts: 17,932
  • Joined: 25-December 09

Re: Read cities from file

Posted 27 September 2013 - 08:26 AM

You should be able to answer the question as to whether or not that snippet is correct. Does the program compile without errors or warnings?

You need to show more effort, or I'm going to close this topic. You may want to start by reviewing your documentation of file input and output in C++ and at least try to give you best effort at writing this program.

Also please use code tags when posting code.


Jim
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1