Starting from:

$29.99

ENSF 614 Lab 4



ENSF 614
Lab 4
Notes:
• This is a group assignment, and you can work with a partner.
Due Date: Wed Oct 18, before 11:59 PM
This is a very shorter lab assignment compared to the other labs, and we have a shorter due date.
Marking scheme
• Exercise A 4 marks
• Exercise B 4 marks
Exercise A: Using C++ library classes, vector and string
The objective of this exercise is to gain some experience in understanding the C++ library classes, vector, and
string.
What to Do:
Download the files lab4ExA.cpp from D2L. In this file there is a declaration of vector <string>. If you
compile and run this program it creates the following output:
ABCD
EFGH
IJKL
MNOP
QRST
Let’s visualize this output as a matrix of letters (5 rows and 4 columns):
A B C D
E F G H
I J K L
M N O P
Q R S T
Your job is to complete the definition of the function called transpose that creates a new object of
vector<string> where its strings are the transpose of the original vector:
A E I M Q
B F J N R
C G K O S
D H L P T
To test your program, you can change the values of the constants ROWS and COLS, in the main function to make
sure your function works with other sizes of the String_Vector.
What to Submit:
Submit the definition of your function transpose and the program’s output.
2
Exercise B: C++ File I/O
The objective of this exercise is to help you understanding the basics of file I/O in C++.
What to Do:
Download the files lab4ExB.cpp from D2L. If you read this file carefully you will realize that this simple C++
program creates a binary file (for example: cities.bin), that contain several records of type struct City.
Each record has two double types represent x and y coordinates of a city on Cartesian Plan, followed by the name
of the city, which is stored as a C-string in an array of characters with 30 elements. The program has several
functions, the implementation of one of them, called print_from_binary, is missing. Your task will be to write
the definition of the missing function. This function is supposed to read the content of the binary file created by the
program, and display the its content (records both on the screen and into a text file, using in the following format:
Name: Calgary, x coordinate: 100, y coordinate: 50
Here is the functions prototype and interface comment:
void print_from_binary(char* filename);
/* PROMISES: uses ifstream library object to open the binary file named
* "filename", reads the content of the file which are objects of struct City
* (one record at a time), and displays them on the screen. It also saves the records
* into a text-file that its name must be filename argument, but with the extension of .txt
*/
What to Submit:
Submit the definition of your function print_from_binary and the content of the generated text file, as part of
your lab report in PDF format.

More products