Advice/help please

hi, i have this assignment to complete but i'm a beginner in c++. i would really appreciate some form of advice/direction to how i could tackle this problem.

the basic objective of this assignment is to Develop further understanding of data structures used in programming;

aims-

1:Create a project and use the main.cpp, unlimited.h, and stringfileread.cpp files in order to build a suitable executable. Test the executable at the command line by using the data files supplied FuelEconomy_short.


header file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#pragma once

#include <iostream>
using namespace std;

#include<valarray>
using namespace std;

#include<fstream>
using namespace std;

#include<string>
using namespace std;

#include<stdio.h>
#include<math.h>
#include<stdlib.h>

typedef double* DoubleArrayPtr;
typedef char* CharArrayPtr;

void binfileread(char *);
void stringfileread(char *);


main.cpp

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
// main.cpp : Defines the entry point for the console application.
//
// A program to bring in binary data from a file and assign that data to an
// array for the purpose of program development.
//
// Usage: unlimited 'file'.txt 'file'.bin
//
#include "unlimited.h"

int main(int argc, char* argv[])
{
	if(argc == 1)
	{

		cout << "Usage: " << argv[0] << "<data file>" << endl;
		exit(0);

	}

	if(argc > 2)
	{
		cout << "Too many input parameters" << endl;
		cout << "Usage: " << argv[0] << " <textfile> <data file>" << endl;
		exit(0);
	}
	
	
	// argc[2] is for the binarray array
	//binfileread(argv[1]);

	// argc[2] is for the chararray array
	stringfileread(argv[1]);

	// Code to be added here

	return 0;

}3 // End of main() 


function(stringfileread

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
 // Function stringfileread
// A function that reads in a text data file
//
// Inputs: pointer to a char
// Outputs: none
//
#include "unlimited.h"

CharArrayPtr cmemblock;
bool cmemallocated;

void stringfileread(char *stringfile)
{

	ifstream textarray(stringfile, ios::in|ios::ate);

	if(textarray.is_open())
	{
		int filesize = textarray.tellg();
		cout << "Text File size is: " << filesize << endl;
		int numberofvalues = filesize / sizeof(char);
		cout << "The number of values from the text file is: " << numberofvalues << endl;

		cmemblock = new char [filesize];
		cmemallocated = true;
		textarray.seekg (0, ios::beg);
		textarray.read(cmemblock, filesize);

		for(int i = 0; i < numberofvalues ; i++)
		{
			cout << cmemblock[i];
		}
		
		textarray.close();
		cout << endl;
		cout << "The complete text file content is in memory" << endl;
		cout << endl;

	// For billbryson.txt, Fs = 8kHz and a 'dit' is about 75ms in duration
	// A'dah' will be three times longer than a 'dit'
	// Choosing a 10ms window (80 samples) should give enough resolution
	//
	// ... Add your Code here .....
	//

	}
	else
	{
		cout << "Unable to open file";
	}

	if(cmemallocated)
	{
		free(cmemblock);
	}

}  // End of stringfileread() 



FuelEconomy_short data text file contains this type of data (literary thousands of these.)

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
 3.1250000e-02
   1.0937500e-01
   1.7187500e-01
   1.8750000e-01
   1.0937500e-01
  -3.1250000e-02
  -1.9531250e-01
  -3.1250000e-01
  -3.2031250e-01
  -2.0312500e-01
   1.5625000e-02
   2.5781250e-01
   4.1406250e-01
   4.2187500e-01
   2.5781250e-01
  -2.3437500e-02
  -3.2031250e-01
  -5.1562500e-01
  -5.2343750e-01
  -3.2031250e-01
   7.8125000e-03
   3.5937500e-01
   5.7812500e-01
   5.8593750e-01
   3.5937500e-01
  -1.5625000e-02
  -4.0625000e-01
  -6.4843750e-01
  -6.5625000e-01
  -4.0625000e-01
   7.8125000e-03
   4.2968750e-01
   6.9531250e-01
   6.9531250e-01


would really appreciate your help guys as i'm truly stuck.
you don't need to use namespace std so many times. Writing it once would be enough.
noted thanks :)

am i right on the right path believing that i have to write some form of input/output file stream, namely "output" as input already exists in the stringfileread function. or am i completely wrong.

thanks
Topic archived. No new replies allowed.