### help me

can someone give me a hand my exam will be after two days
pls.

Your program should contain at least the following functions with suitable parameters:
 LoadInfo(string city[],int yesTemps[],int todayTemps[]): reads the city name and the temperatures
for the yesterday and today for each city from an input file named "temps.dat", and stores city names
in 1D array of strings and temperatures in two 1D arrays. The function should count and return the
number of cities in the input file.
 PredictCitiesTemps(int yesTemps[],int todayTemps[],int tomorrowTemps[],int n): receives the
temperatures for yesterday and today for all cities using two 1D arrays and uses the random number
generator to predict tomorrow’s temperature for each city. It computes the tomorrow’s temperature
for a given city as the average temperature for the previous two days (yesterday and today) plus a
random number between –3 and +3. For example the average temperature for Muscat city is
(30+32)/2=31. Therefore, tomorrow’s temperature in Muscat can be between 31-3=28 and 31+3= 34.
 Display(string city[],int yesTemps[],int todayTemps[],int tomorrowTemps[],int n): displays the
city name and the temperatures for the 3 days for each city in the screen using a tabular format as
shown in figure 2.
 getHottestCity(string city[],int temps[],int n): accepts city names and the temperatures for a given
day (either for yesterday, today, or tomorrow) as two arrays and returns the name of the city with the
highest temperature.
 PrintToExcelFile(string city[],int tomorrowTemps[],int n): writes the city name and tomorrow’s
temperature for each city into an Excel file named "predTemp.xls " as shown in figure 3. To create
an Excel document, you need to name your document with ".xls" extension and separate columns
using the Tab key ("\t" in C++).
Why don't you attempt the problem first and then post a code of what you have done and need help with. That way it wouldn't seem like you're asking us to do your homework for you.
i do the first function but doesn't work, i'm from different major and this thing is completely new to me if you can help i be grateful to you

#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

const int max_size=100;

int LoadInfo(string city[], int yesTemps[], int todayTemps[]);
int PredictCitiesTems(int yesTemps[], int todayTemps[], int tomorrwTemps[], int n);

int main()
{
string city[max_size];
int yesTemps[max_size];
int todayTemps[max_size];

cout<<" Numbers of cities is "<< sizeof(city);

system("pause");

return 0;

}

int LoadInfo(string city[], int yesTemps[], int todayTemps[])
{

ifstream fin;
fin.open("temps.dat");
int n=0;

fin >>city[n]>>yesTemps[n],todayTemps[n];
while(!fin.eof())
{

n++;
fin >>city[n]>>yesTemps[n],todayTemps[n];
}

int num_elements=sizeof(city[n]);

return 0;

}
Last edited on
`int Num_elements=LoadInfo(city,yesTemps,todayTemps);`

On this line you are assigning the return value of the function to Num_elements. However, the function returns 0. If you want the actual number of elements of the city array you'll have to return num_elements itself from the function. However, the way you have it written it's only return the size of an element. I forget exactly how you get the number of elements from an array but basically you have to divide the size of the array by the size of a single element, something like ` return (sizeof(city)/sizeof(city[0]))`. If I remember correctly that is. :)

Also, this way you are returning the value itself and don't need the num_elements variable in the function. Not a huge different, but it's a little more elegant of a solution.
Last edited on
Topic archived. No new replies allowed.