Classes

So I've been researching for a couple hours tonight and I have an idea of how to do my assignment correctly and started my class so far and made it public. Although my instructor has not specified public or private I want to do this the right way.

This is my assignment:
This week we add C++ to your Week #1 program, in the form of a class you define, and use of an STL container class, vector.
• Create a class that “wraps” or “hides” the information from flightRec. So your class will convert each char array from the flightRec struct into strings, and also have methods to access

each data member. You can name your class whatever you want, although you should keep Meyer's general guidelines in mind (no verb names, please). In this document, I am calling the class an OverFlight.
• Your constructor can take the flightRec struct as a parameter, and/or you can set the needed members of your class from the corresponding elements of flightRec using methods you code in your OverFlight class.
• Using one of the approaches above, convert the char arrays from the struct to strings stored within OverFlight, and convert the binary time-stamp in the struct to a human-readable string as well.
• Add each new instance of OverFlight to a Vector that holds all the OverFlights from the acars.bin file.
• Iterate through the vector, and print out the flightNum, originAirportCode, destAirportCode and dateString (in human-readable format) as a CSV text file. In other words, your output will look a lot like the Week #1 example, except that the time-stamp will be formatted as a human- readable date string.
The C standard library provides functions for converting a POSIX time into a time struct, and subsequently into a human readable string as well. This is how you get a human-readable date from the time-stamp stored in each flightRec struct.

Starting with my class that I have created could anyone tell me if i'm even on the right path (and yes I know there is not much but I was trying some stuff that did not work so this is my starting point)


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
  #include <stdlib.h>
#include <iostream>
#include <cstdio>
#include <fstream>
#include <vector>
#include <iomanip>
#include <string>

using namespace std;

struct FlightRec {
	char flightNum[7];
	char originAirportCode[5];
	char destAirportCode[5];
	int dateStamp;
};

class overFlight{
public:
	string flightNum[7];
	string originAirportCode[5];
	string desAirportCode[5];

};

int main()
{
	fstream myfile;
	struct FlightRec flights;
	overFlight flightInfo;

	myfile.open("C:\\Users\\ChristopherJ\\Desktop\\Chris School\\C++\\acars.bin", ios::in | ios::binary);


	if (!myfile.is_open())	{
		cerr << "error";
		return -1;
	}
	
	while (!myfile.eof())	{
		myfile.read((char*)(&flights), sizeof(flights));
		cout << left << setw(7) << flights.flightNum << left << setw(5) << flights.originAirportCode << left << setw(5) << flights.destAirportCode << left << setw(12) <<
			flights.dateStamp << endl;
	}
	 
	myfile.close();

	return 0;
}
Make the members of overFlight private.
Topic archived. No new replies allowed.