Course list http://www.c-jump.com/bcc/
In this lab we finish upgrading the Scratch Pad app to the capability of saving and loading data to and from disk files:
There is no prototype for this lab. Download and unzip c255_lab21_load_save.zip
Open c255_lab21.sln solution in Visual Studio. Compile and test the program.
Use WinMerge to compare Lab 20 and Lab 21 folders. Click WinMerge menu
File -> Open
and specify locations of the two folders. In WinMerge comparison view:
Double-click the CMainWindow.cpp. There is new code in the "Load" and "Save" callback functions:
draw_box->save_to_file( filepath ); draw_box->load_from_file( filepath );
Because load and save operations must deal with all types of drawing primitives, I decided to add those functions to the interface of the CDrawBox class.
Double-click the CDrawBox.h. There is new code in support of
new #includes for working with files and converting integer values to and from string values:
#include <string> #include <sstream> #include <fstream>
operator<< for streaming data from the drawing primitives to a standard library stream device
CDrawBox::save_to_file()
CDrawBox::load_from_file()
CPrimitiveBase class got two new operations:
string get_type() // L=line C=circle, R=rectange, and so on string to_string() // converts shape to string: "L 200 200 300 300"
Double-click the CDrawBox.cpp and examine the code. The implementation of new functions is to be discussed in details at the lecture. The topics include call sequence diagrams, loading and saving files, and C++ operator overloading.
This is a self-learning lab. There are no files to submit. Make sure to complete all required steps to build and test the project on your own home computer.