Solved OOP244 Workshop #1: Modules  In process of doing your first workshop, in part 1 section you are to sub-divide a program

$30.00

Original Work ?
Category: Tags: , You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (1 vote)

In process of doing your first workshop, in part 1 section you are to sub-divide a program into modules, compile each module separately and construct an executable from the results of each compilation.

## 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.

## Submission Policy

The workshop is divided into one coding part and one non-coding part:

– Part 1 (**LAB**): A step-by-step guided workshop, worth 100% of the workshop’s total mark
> Please note that the part 1 section is **not to be started in your first session of the week**. You should start it on your own before the day of your class and join the first session of the week to ask for help and correct your mistakes (if there are any).
– Part 2 (reflection): non-coding part. The reflection doesn’t have marks associated with it but can incur a **penalty of max 40% of the whole workshop’s mark** if your professor deems it insufficient (you make your marks from the code, but you can lose some on the reflection).

## Due Dates
Part 1 (lab) is due 2 days after your lab day and Part 2 (Reflection) is due 6 days after your lab day.

The Due dates depend on your section. Please choose the “-due” option of the submitter program to see the exact due date of your section:

> Note that the submission usually opens by the end of Monday.
“`bash
~profname.proflastname/submit 2??/wX/pY_sss -due<ENTER>
“`
– Replace **??** with your subject code (`00 or 44`)
– Replace **X** with Workshop number: [`1 to 10`]
– Replace **Y** with the part number: [`1 or 2`]
– Replace **sss** with the section: [`naa, nbb, nra, zaa, etc…`]

## Late penalties
You are allowed to submit your work up to 2 days after the due date with a 30% penalty for each day. After that, the submission will be closed and the mark will be zero.

## Citation

Every file that you submit must contain (as a comment) at the top:<br />
**your name**, **your Seneca email**, **Seneca Student ID** and the **date** when you completed the work.

### For work that is done entirely by you (ONLY YOU)

If the file contains only your work or the work provided to you by your professor, add the following message as a comment at the top of the file:

> I have done all the coding by myself and only copied the code that my professor provided to complete my workshops and assignments.

### For work that is done partially by you.

If the file contains work that is not yours (you found it online or somebody provided it to you), **write exactly which part of the assignment is given to you as help, who gave it to you, or which source you received it from.** By doing this you will only lose the mark for the parts you got help for, and the person helping you will be clear of any wrongdoing.

> – Add the citation to the file in which you have the borrowed code
> – In the ‘reflect.txt` submission of part 2 (Reflection), add exactly what is added to which file and from where (or whom).

> :warning: This [Submission Policy](#submission-policy) only applies to the workshops. All other assessments in this subject have their own submission policies.

### If you have helped someone with your code

If you have helped someone with your code. Let them know of these regulations and in your ‘reflect.txt’ of part 2 (Reflection), write exactly which part of your code was copied and who was the recipient of this code.<br />By doing this you will be clear of any wrongdoing if the recipient of the code does not honour these regulations.

## Compiling and Testing Your Program

All your code should be compiled using this command on `matrix`:

“`bash
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`):

“`bash
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 **seneca** namespace, unless instructed otherwise.

# Part 1 – LAB (100%)

***Shopping List*** is a program that keeps track of your shopping list up to 15 items. You can add items to the list, remove and check the items you bought. Also, you can remove all the checked items and clear the list.

Here is a sample execution of the program

## LAB Execution example

“`text
–>>> My Shopping List <<<–
1-[ ]Oranges qty:(4)
2-[ ]Apples qty:(4)
3-[ ]Bananas qty:(10)
4-[ ]Frozen Strawberries qty:(1)
5-[X]Milk 3% qty:(2)
6-[ ]Milk Skim qty:(1)
7-[ ]Lundry Detergent liquic qty:(1)
8-[ ]Lundry Detergent pods qty:(1)
—————————-
1- Toggle bought Item
2- Add Shopping Item
3- Remove Shopping Item
4- Remove bought Items
5- Clear List
0- Exit
> 1
Item number: 3
–>>> My Shopping List <<<–
1-[ ]Oranges qty:(4)
2-[ ]Apples qty:(4)
3-[X]Bananas qty:(10)
4-[ ]Frozen Strawberries qty:(1)
5-[X]Milk 3% qty:(2)
6-[ ]Milk Skim qty:(1)
7-[ ]Lundry Detergent liquic qty:(1)
8-[ ]Lundry Detergent pods qty:(1)
—————————-
1- Toggle bought Item
2- Add Shopping Item
3- Remove Shopping Item
4- Remove bought Items
5- Clear List
0- Exit
> 4
Removing bought items, are you sure?
(Y)es/(N)o: y
–>>> My Shopping List <<<–
1-[ ]Oranges qty:(4)
2-[ ]Apples qty:(4)
3-[ ]Frozen Strawberries qty:(1)
4-[ ]Milk Skim qty:(1)
5-[ ]Lundry Detergent liquic qty:(1)
6-[ ]Lundry Detergent pods qty:(1)
—————————-
1- Toggle bought Item
2- Add Shopping Item
3- Remove Shopping Item
4- Remove bought Items
5- Clear List
0- Exit
> 2
Item name: Tooth Paste
Quantity: 3
–>>> My Shopping List <<<–
1-[ ]Oranges qty:(4)
2-[ ]Apples qty:(4)
3-[ ]Frozen Strawberries qty:(1)
4-[ ]Milk Skim qty:(1)
5-[ ]Lundry Detergent liquic qty:(1)
6-[ ]Lundry Detergent pods qty:(1)
7-[ ]Tooth Paste qty:(3)
—————————-
1- Toggle bought Item
2- Add Shopping Item
3- Remove Shopping Item
4- Remove bought Items
5- Clear List
0- Exit
> 0
“`

## Step 1: *Test the Program*

### On Visual Studio
– Open Visual studio and create an Empty C++ Windows Console Project:<br />
![Empty Project](images/emptyproj.png)
– In VS, (if not open already) open Solution Explorer (click on View/Solution Explorer) and then add w1p1.cpp file to your project:<br />
-Right-click on **“Source Files”**<br />
-Select **“Add/Existing Item”**<br />
-Select **w1p1.cpp** from the file browser<br />
-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](https://students.senecapolytechnic.ca/spaces/186/it-services/wiki/view/1024/vpn)
– Upload **w1p1.cpp** and **shoppinglist.csv** 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:
“`bash
g++ w1p1.cpp -Wall -std=c++11 -o ws<ENTER>

-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:
“`bash
ws<ENTER>
“`

## Step 2: Create the Modules
### On Windows, using Visual Studio (VS)
In the solution explorer, add five new modules to your project:
– **shoppingListApp**; A module to hold the main() function and its relative functions and constant value. (see below)
– **File**; A module to hold the functions and global variables related to File processing.
– **ShoppingList**; A module to hold the direct shopping list-related functions, global variables and constants.
– **ShoppingRec**; A module to hold the shopping record-related functions, variables, constants and the **ShoppingRec** structure.
– **Utils**; A module to hold the general utility functions for the applications. This file may be moved to other workshops and assignments if needed.

The **shoppingListApp** module has an implementation (.cpp) file but no header file. The **File**, **ShoppingList**, **ShoppingRec** and **Utils** modules have both implementation (.cpp) and header (.h) files:

#### Header files
Add **File.h**, **ShoppingList.h**, **ShoppingRec.h** and **Utils.h** to the “Header Files” directory (right-click on “Header Files” and select “Add/New Item” and add a header file)<br />
Make sure you add the compilation safeguards and also have all the C++ code in the last four modules in a namespace called “seneca”.

##### Compilation Safeguards
**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:
“`C++
#ifndef NAMESPACE_HEADERFILENAME_H // replace with relevant names
#define NAMESPACE_HEADERFILENAME_H

// Your header file content goes here

#endif
“`
If the name isn’t 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 wouldn’t have been defined), the check fails, the code proceeds no further and the header is not included again.<br />
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).<br />
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 isn’t the standard for our class. Follow the standard for safeguards as described in your class.<br />
[Compilation Safegards](https://www.youtube.com/watch?v=EGak2R7QdHo): https://www.youtube.com/watch?v=EGak2R7QdHo

#### CPP Source Files
Add **shoppingListApp.cpp**, **File.cpp**, **ShoppingList.cpp**, **ShoppingRec.cpp** and **Utils.cpp** to the “Source Files” directory (right-click on “Source Files” and select “Add/New Item” and add a C++ file)<br />

## Step 3: The main Module

### shoppingListApp Module
(The module holding the **main** function)

**shoppingListApp.cpp** file should have these include and namespace statements:
“`C++
#include <iostream>
#include <cstdlib>
#include “File.h”
#include “ShoppingList.h”
#include “Utils.h”
using namespace std;
using namespace seneca;
“`
#### Constant value declaration
Add the following constant value to the file
“`C++
// set to false when compiling on Linux
const bool APP_OS_WINDOWS = true;
“`

#### module Functions
“`Text
main
listMenu
“`

## Step 4: organize the code in modules
———————————————–

Separate the rest of the functions in **w1p1.cpp** and copy them into the remaining modules as described below. Copy the body of the functions into the cpp files and the prototypes into the header files.

#### Guideline for creating modules
##### #includes
Avoid unnecessary random includes and only include a header file in a cpp file in which the header file functions are called or the header file definitions are used. <br />
Do not include a header file inside another header file unless it is absolutely necessary.

##### Global variables (file scope variables)
Global variable declarations must be in the CPP files to be kept invisible to other modules

##### Structure definitions
Structure definitions must be kept in the header file to be visible to all the modules using it.

##### Constant value declarations
The Constant value declarations are to be added to the file they are used in; if they are used in a header file, they must be added to the header file otherwise they must be added to the CPP file they are used in.

##### Namespace
All your code (in header files and CPP files) must be surrounded by the **seneca** namespace except in the module holding the **main** function.<br />
The **main** module should use the **seneca** namespace (“`using namespace seneca;“`).<br />
> important: Never use the **using** statement in a header file.

### ShoppingRec module
This module contains the ***ShoppingRec*** Structure.
#### Functions
“`Text
getShoppingRec
displayShoppingRec
toggleBoughtFlag
isShoppingRecEmpty
“`
#### Constant Value Declarations
“`Text
MAX_QUANTITY_VALUE
MAX_TITLE_LENGTH
“`

### Utils module
#### Functions
“`Text
flushkeys
ValidYesResponse
yes
readCstr
readInt
“`
### ShoppingList module
#### Functions
“`Text
loadList
displayList
removeBoughtItems
removeItem
saveList
clearList
toggleBought
addItemToList
removeItemfromList
listIsEmpty
“`
#### Constant Value Declaration
“`Text
MAX_NO_OF_RECS
“`
#### Global Variable Declarations
“`C++
ShoppingRec recs[MAX_NO_OF_RECS]
int noOfRecs
“`
### File module
#### Functions
“`Text
openFileForRead
openFileForOverwrite
closeFile
freadShoppingRec
fwriteShoppintRec
“`
#### Constant Value Declarations
“`C++
const char* const SHOPPING_DATA_FILE
“`
#### Global Variable Declarations
“`C++
FILE* sfptr
“`
——————————-
## Step 5: Testing
### Testing the Shopping List Application
#### Windows
To test that you have done this correctly, you can compile each module separately, by right-clicking on ***shoppingListApp.cpp**, **File.cpp**, **ShoppingList.cpp**, **ShoppingRec.cpp** and **Utils.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:
“`Bash
g++ File.cpp –Wall -std=c++11 –c<ENTER>
“`
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.
#### Matrix (Linux)
On Linux, in your matrix account, upload all the module files and the data file **shoppinglist.csv** to your matrix account.

Modify **shoppingListApp.cpp** and set the APP_OS_WINDOWS constant value to false:
“`C++
// set to false when compiling on Linux
const bool APP_OS_WINDOWS = false;
“`
and compile the source code using the following command.

“`Bash
g++ shoppingListApp.cpp File.cpp ShoppingList.cpp ShoppingRec.cpp Utils.cpp -Wall -std=c++11 -o ws<ENTER>
“`
Run the program like before with the **shoppinglist.csv** file and make sure that everything still works properly.

## Submission Process:

### Professor’s main module

<a href=”Part1/shoppingListApp_prof.cpp” target=”_blank”>Prof’s tester module</a>

### Data entry

To test and demonstrate the execution of your program use the same data as shown in the [LAB Execution example](#lab-execution-example) that is listed below:

“`text
1
3
4
y
2
Tooth Paste
3
0
“`

 

### Submission

Upload the files listed above to your `matrix` account. Compile and run your code using the `g++` compiler as shown in [Compiling and Testing Your Program](#compiling-and-testing-your-program) and make sure that everything works properly.

Then, run the following command from your matrix account

“`bash
~profname.proflastname/submit 2??/wX/pY_sss <ENTER>
“`
– Replace **??** with your subject code (`00 or 44`)
– Replace **X** with Workshop number: [`1 to 10`]
– Replace **Y** with the part number: [`1 or 2`]
– Replace **sss** with the section: [`naa, nbb, nra, zaa, etc…`]

and follow the instructions.

> :warning:**Important:** Please note that a successful submission does not guarantee full credit for this workshop. If the professor is not satisfied with your implementation, your professor may ask you to resubmit. Re-submissions will attract a penalty

# Part 2: Reflection

Study your final solutions for each deliverable of the workshop **and the most recent milestones of the project if applicable**, reread the related parts of the course notes, and make sure that you have understood the concepts covered by this workshop. **This should take no less than 30 minutes of your time and the result is suggested to be between 150 to 300 words in length.**

Create a file named `reflect.txt` that contains your detailed description of the topics that you have learned in completing this workshop and **the project milestones if applicable** and mention any issues that caused you difficulty.

### Reflection Submission Process:

Upload `reflect.txt` to matrix containing the reflection

Then, run the following command from your matrix account

“`bash
~profname.proflastname/submit 2??/wX/pY_sss <ENTER>
“`
– Replace **??** with your subject code (`00 or 44`)
– Replace **X** with Workshop number: [`1 to 10`]
– Replace **Y** with the part number: [`1 or 2`]
– Replace **sss** with the section: [`naa, nbb, nra, zaa, etc…`]

and follow the instructions.

> :warning:**Important:** Please note that a successful submission does not guarantee full credit for this workshop. If the professor is not satisfied with your implementation, your professor may ask you to resubmit. Re-submissions will attract a penalty.