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?
Read cities from file
Page 1 of 18 Replies - 1259 Views - Last Post: 27 September 2013 - 08:26 AM
Replies To: Read cities from file
#2
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.
#3
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.
How do i manipulate them?
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.
#4
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?
#5
Re: Read cities from file
Posted 27 September 2013 - 08:15 AM
#6
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
Jim
#7
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.
#8
Re: Read cities from file
Posted 27 September 2013 - 08:21 AM
** Renamed title to be more descriptive **
#9
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
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
Page 1 of 1

New Topic/Question
Reply


MultiQuote






|