Question
PLEASE I NEED HELP WITH THIS!! Workshop #1: Modules (V1.1) DIY sort is changed to be sorted on stno (ascending) instead of GPA If you
PLEASE I NEED HELP WITH THIS!!
Workshop #1: Modules
(V1.1) DIY sort is changed to be sorted on stno (ascending) instead of GPA
If you have already successfully submitted the DIY using GPA sort, you do not need to resubmit your work; the first submission is valid
In process of doing your first workshop, in the lab (part 1) you are to sub-divide a program into modules, compile each module separately and construct an executable from the results of each compilation. In DIY (part 2) you are to write a modular program based on your knowledge of ipc144 subject and what you learnt up to now in C++.
Learning Outcomes
Upon successful completion of this workshop, you will have demonstrated the abilities to:
organize source code into modules, using header and implementation files;
compile and link modular programs;
distinguish the contents of a header and an implementation file;
describe to your instructor what you have learned in completing this workshop.
Compiling and Testing Your Program
All your code should be compiled using this command on matrix:
g++ -Wall -std=c++11 -g -o ws file1.cpp file2.cpp ...
-Wall: the compiler will report all warnings
-std=c++11: the code will be compiled using the C++11 standard
-g: the executable file will contain debugging symbols, allowing valgrind to create better reports
-o ws: the compiled application will be named ws
After compiling and testing your code, run your program as follows to check for possible memory leaks (assuming your executable name is ws):
valgrind --show-error-list=yes --leak-check=full --show-leak-kinds=all --track-origins=yes ws
--show-error-list=yes: show the list of detected errors
--leak-check=full: check for all types of memory problems
--show-leak-kinds=all: show all types of memory leaks identified (enabled by the previous flag)
--track-origins=yes: tracks the origin of uninitialized values (g++ must use -g flag for compilation, so the information displayed here is meaningful).
To check the output, use a program that can compare text files. Search online for such a program for your platform, or use diff available on matrix.
Note: All the code written in workshops and the project must be implemented in the sdds namespace, unless instructed otherwise.
LAB (50%)
50 top movies of all times "genre" search is a program that searches through 50 movies records that are saved in a file, based on the users inquiry on the genre of the movie.
For example if the user enters Comedy, the program lists all the movies with Comedy in their list of genres.
LAB Execution example
Welcome to 50 top movies of all times "genre" search. Enter the movie genre to start the search: Anim1- Finding Nemo [2003], G, duration: 100 minutes, Rating: 8.1/10 (Animation, Adventure, Comedy) Do another search? (Y)es: y Enter the movie genre to start the search: Comedy 1- Life Is Beautiful [1997], PG, duration: 116 minutes, Rating: 8.6/10 (Comedy, Drama, Romance) 2- The Intouchables [2011], 14A, duration: 112 minutes, Rating: 8.5/10 (Biography, Comedy, Drama) 3- My Sassy Girl [2001], PG, duration: 137 minutes, Rating: 8/10 (Comedy, Drama, Romance) 4- Back to the Future [1985], PG, duration: 116 minutes, Rating: 8.5/10 (Adventure, Comedy, Sci-Fi) 5- Finding Nemo [2003], G, duration: 100 minutes, Rating: 8.1/10 (Animation, Adventure, Comedy) Do another search? (Y)es: n Goodbye!
Step 1: Test the Program
On Visual Studio
Open Visual studio 2019 and create an Empty C++ Windows Console Project:
In VS, (if not open already) open Solution Explorer (click on View/Solution Explorer) and then add w1p1.cpp file to your project: -Right click on Source Files -Select Add/Existing Item -Select w1p1.cpp from the file browser -Click on Ok
Now you can run the program by selecting Debug/Start Without Debugging or pressing the Ctr-F5 button.
On Linux, in your Matrix account
Connect to Seneca with Global Protect VPN
Upload w1p1.cpp and movies.dat to your matrix account (Ideally to a designated directory for your workshop solutions). Then, enter the following command to compile the source file and create an executable called ws:
g++ w1p1.cpp -Wall -std=c++11 -o ws-Wall: display all warnings -std=c++11: compile using C++11 standards -o ws: name the executable ws
Type the following to run and test the execution:
ws
Step 2: Create the Modules
On Windows, using Visual Studio (VS)
In solution explorer, add three new modules to your project:
50Best; A module to hold the main() function and its relative functions. (see below)
File; A module to hold the functions and global variables related to File processing.
Movie; A module to hold movie functions and global variables which have no direct relation to the File analysis in the program.
The 50Best module has an implementation (.cpp) file but no header file. The File and Movie modules have both implementation (.cpp) and header (.h) files:
Add File.h and Movie.h to the Header Files directory (right click on Header Files and select Add/New Item and add a header file) Make sure you add the compilation safeguards and also have all the C++ code in File and Movie modules in a namespace called sdds.
Important: Note that, you are not allowed to use the using statement in a header file. For example, in a header file you are not allowed to write:
using namespace std; // not allowed in a ".h" file
compilation safeguards refer to a technique to guard against multiple inclusion of header files. It does so by applying macros that check against a defined name:
#ifndef NAMESPACE_HEADERFILENAME_H // replace NAMESPACE and HEADERFILENAME with relevant names #define NAMESPACE_HEADERFILENAME_H // Your header file content goes here #endif
If the name isnt yet defined, the #ifndef will allow the code to proceed onward to then define that same name. Following that the header is then included. If the name is already defined, meaning the file has been included prior (otherwise the name wouldnt have been defined), the check fails, the code proceeds no further and the header is not included again. Compilation safeguards prevent multiple inclusions of a header in a module. They do not protect against including the header again in a different module (remember that each module is compiled independently from other modules). Additionally, here is an instructional video showing how the compiler works and why you need these safeguards in all of your header files. Do note that this video describes the intent and concept behind safeguards, the naming scheme isnt the standard for our class. Follow the standard for safeguards as described in your class. Compilation Safegards: https://www.youtube.com/watch?v=EGak2R7QdHo
-Add 50Best.cpp, File.cpp and Movie.cpp to the Source Files directory (right click on Source Files and select Add/New Item and add a C++ file)
50Best.cpp Module should have only these include and namespace statements:
#include#include "Movie.h" using namespace std; using namespace sdds;
and contain only the following functions:
flushkeys yes main
Separate the rest of the functions in w1p1.cpp and copy them into FILE and Movie modules as described below. Copy the body of the functions into the cpp files and the prototype into the header files. Note that the global variables must be in the cpp files to be kept invisible to other modules, but the structure difinitions must be kept in the header file to be visible to all the other modules using it
Movie module
Contains the Movie Structure, the movies global array of Movies and the following functions:
loadMovies; hasGenre; displayMovie; displayMoviesWithGenre;
File Module
Contains the fptr FILE pointer as global variable and following functions
openFile closeFile readTitle readYear readMovieRating readDuration readGenres readConsumerRating
To test that you have done this correctly, you can compile each module separately, by right clicking on 50Best.cpp, File.cpp and Movie.cpp separately and select compile from the menu. If the compilation is successful, most likely you have done it correctly.
The equivalent of this on matrix is to add -c to the compile command:
g++ File.cpp Wall -std=c++11 c
This example will only compile File.cpp and will not create an executable.
Now remove w1p1.cpp from the project. You can do this by right clicking on the filename in solution explorer and selecting remove in the menu (make sure you do not delete this file but only remove it). Compile and run the project (as you did before in Step 1) and make sure everything works.
On Linux, in your matrix account, upload the five files from earlier (File.cpp, File.h, Movie.cpp, Movie.h and 50Best.cpp) and movies.dat to your matrix account and compile the source code using the following command.
g++ File.cpp Movie.cpp 50Best.cpp -Wall -std=c++11 -o ws
Run the program like before with the movies.dat file and make sure that everything still works properly.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started