Hi, I'm New and I have a Question redaring Memory Maps
Apr 12, 2011 at 5:21am UTC
Hi everyone,
Here is the code I wrote myself.
How would I make a map of memory?
I need to draw a map of memory at the point just before the closing brace for the function inputFmFile().
Also, how would I draw a map of memory at the point when the program first enters the function temp().
I really need help and would definitely appreciate it.
Love,
Ingrid
tempFns.h
1 2 3 4 5 6 7 8 9 10
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
const int MaxDays = 31;
const int MaxTimes = 5;
void tempAvg (double [] [MaxTimes], int , int );
void inputFmFile (double [][MaxTimes], int &, int &);
void outputData (double [][MaxTimes], int , int );
tempDriver.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#include "tempFns.h"
int main () {
double temperatures [MaxDays][MaxTimes];
int numDays = 0;
int numTimes = 0;
inputFmFile (temperatures, numDays, numTimes);
cout << "Temperature data before calculating averages." << endl;
outputData (temperatures, numDays, numTimes);
cout << endl;
tempAvg (temperatures, numDays, numTimes);
cout << "Temperature data after calculating averages." << endl;
outputData (temperatures, numDays, numTimes+1);
cout << endl;
cout << "Bye!" << endl;
return 0;
}
Definitions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
#include "tempFns.h"
void tempAvg (double tempArray [MaxDays] [MaxTimes], int days, int times) {
if (days > MaxDays || days < 28 || times >= MaxTimes) exit (1);
double sum = 0;
for (short i = 0; i < days; i++) {
for (short j = 0; j < times; j++) {
sum += tempArray [i] [j];
}
tempArray [i] [MaxTimes] = sum / times;
sum = 0;
}
}
void inputFmFile (double tempArray [][MaxTimes], int &days, int ×)
{
bool worked = true ;
string inFileName;
char * name = "" ;
ifstream inStr;
do {
cout << "Enter name of file to read from: " ;
cin >> name;
inFileName = name;
inStr.open (inFileName.c_str());
if (inStr.fail())
{
cerr << "Error opening file. Try again." << endl;
inStr.clear();
worked = false ;
}
else
worked = true ;
} while (!worked);
inStr >> days >> times;
for (int i=0; i < days; i++)
for (int j=0; j < times; j++)
inStr >> tempArray [i][j];
for (int i=0; i < days; i++)
tempArray [i][times] = 0.0;
}
void outputData (double tempArray [][MaxTimes], int days, int times)
{
cout << endl << "The temperatures for the month are : " << endl;
cout.setf(ios::fixed);
cout.precision (2);
cout << setw(9) << "Day" ;
for (int i=0; i < times-1; i++)
cout << setw(8) << "Temp" << i+1;
cout << setw(8) << "Average" << endl;
for (int i=0; i < days; i++) {
cout << setw(9) << i+1;
for (int j=0; j < times; j++)
cout << setw(9) << tempArray [i][j];
cout << endl;
}
}
Apr 12, 2011 at 7:43am UTC
What is "map of memory" supposed to mean? Memory map is usually for inter process communication. I think that's not what you want? Make it more specific. And there's no 'function temp()'
Topic archived. No new replies allowed.