User Tools

Site Tools


haas:summer2017:cprog:projects:oop0

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
haas:summer2017:cprog:projects:oop0 [2017/08/01 13:38] wedgehaas:summer2017:cprog:projects:oop0 [2017/08/01 14:05] (current) wedge
Line 67: Line 67:
 In your programs, you will be performing message passing when dealing with your classes. In your programs, you will be performing message passing when dealing with your classes.
  
-The "Datarefers to the actual data you wish to store or useIn OO we have more attributes we can assign to this data- and that refers to its accessibility. Public, Private, and Protected. Public data is just that-- available for all to see. Private data is only accessible to the other members and data WITHIN the particular class. (A class cannot access neighbor class's private data).+====Access Control==== 
 +Using classes we also have the "**public**and "**private**" functionality available to further control how our data is accessedC++ provides us with a powerful means of controlling data access to our class. 
 + 
 +Public access control is just that-- available for all to see. Private access means only accessible to the other class members WITHIN that particular class. 
 + 
 +It is sometimes preferable for different levels of a program to be programmed by different people. Large database applications can often have several different groups of people working on different tasks. 
 + 
 +Instead of giving every programmer the entire program to do with as they please, each group can work on their specific component, and release it to the other groups to use in the implementation of their component. Distributing such things in binary form is not uncommon. Look at the world of proprietary software, where no source code is available. You must be able to use their binary code and any documentation the vendor may provide in order to design your solution. You cannot view the source code of the various function calls to see how they work. Instead, you must rely on the documentation, knowing what parameters to send in and what gets returned (if anything) and trust that the code works as the documentation indicates it does. 
 + 
 +In the Open Source world, lack of source code isn't as much of problem, but the concepts of data access are still very important. A program may still have several components to it, and for security purposes the file-save module probably SHOULDN'T have direct access to user passwords. Protecting data is still very important for organizing a solution, no matter what your source code availability is. 
 + 
 +There are some additional access control attributes available: **protected** and **friend**. Protected access control is utilized more in inheritance, and the "friend" attribute is used in extraneous circumstances when a clear relationship cannot be established (also in inheritance).
  
 =====Programming in C++===== =====Programming in C++=====
Line 261: Line 272:
 The **-o** argument to **g++** indicates the name of the output file. Since there is only one file in this case, the compiler automatically performs the assembling and linking steps for us.  The **-o** argument to **g++** indicates the name of the output file. Since there is only one file in this case, the compiler automatically performs the assembling and linking steps for us. 
  
-=====Shapes===== +=====rectangle class===== 
-In the **shapes/** subdirectory of the CPROG Public Directory (**/var/public/cprog/**), you will find a file called **rectangle.cc**. Copy this to your **~/src/cprog/** subdirectory as follows:+In the **oop0/** subdirectory of the CPROG Public Directory (**/var/public/summer2017/cprog/**), you will find a file called **rectangle.cc**:
  
 <cli> <cli>
Line 271: Line 282:
 Please read through this source code, compile, and run the program. Make sure you understand what is going on. Please read through this source code, compile, and run the program. Make sure you understand what is going on.
  
-=====Questions===== +=====Program===== 
-  - What are the member functions of the Rectangle class? +We've got the accessor functions of **getLength()**/**setLength()** and **getWidth()**/**setWidth()** for checking and setting the current values of the particular rectangle's length and width, and **area()** and **perimeter()** for performing useful actions on that data. You'll notice all those member functions are empty. Go ahead and finish the implementation of this program:
-  - If dealing with a triangle, what are the formulas for perimeter and area? +
-  - With a trapezoidwhat are the formulas for perimeter and area?+
  
-=====Program 1=====+  * implement the member functions (keeping any function parameter names identical to how you received them) 
 +  * duplicate the output code block in main(), adapting as appropriate for box2, box3, and box4. 
 +  * Modify the program by adding **triangle** and **trapezoid** classes. Be sure to define the appropriate member functions and member data. To avoid confusion, be sure to employ the scoping operator (::). Also be sure that each "shape" has the ability to set the **length/width** as well as to retrieve its **area** and **perimeter**.
  
-We've got the accessor functions of **getLength()** and **getWidth()** for checking the current values of the particular rectangle's length and width, but how about setting them after the fact? Go ahead and add to this program: +=====Review of Compiling/Executing=====
- +
-  * define and implement two new member functions- **setLength()** and **setWidth()** and adjust your output accordingly to prove that they do what they are supposed to do. +
-  * Modify the program by adding **Triangle** and **Trapezoid** classes. Be sure to define the appropriate member functions and member data. To avoid confusion, be sure to employ the scoping operator (::). Also be sure that each "shape" has the ability to set the **length/width** as well as to retrieve its **area** and **perimeter**. +
-  * First make your changes to have everything in one big source file. Make sure this compiles and works as expected. Once you have this done, break apart your code into separate files (.h and .cc files), breaking all the code up as efficiently as you see fit (perhaps per each shape). Submit both the single (all-in-one) file, and the multi-file versions of your programs. +
- +
- +
-======Access Control====== +
-Using classes we also have the "public" and "private" functionality available to further control how our data is accessed. C++ provides us with a powerful means of controlling data access to our class. +
- +
-It is sometimes preferable for different levels of a program to be programmed by different people. Large database applications can often have several different groups of people working on different tasks. +
- +
-Instead of giving every programmer the entire program to do with as they please, each group can work on their specific component, and release it to the other groups to use in the implementation of their component. Distributing such things in binary form is not uncommon. Look at the world of proprietary software, where no source code is available. You must be able to use their binary code and any documentation the vendor may provide in order to design your solution. You cannot view the source code of the various function calls to see how they work. Instead, you must rely on the documentation, knowing what parameters to send in and what gets returned (if anything) and trust that the code works as the documentation indicates it does. +
- +
-In the Open Source world, lack of source code isn't as much of a problem, but the concepts of data access are still very important. A program may still have several components to it, and for security purposes the file-save module probably SHOULDN'T have direct access to user passwords. Protecting data is still very important for organizing a solution, no matter what your source code availability is. +
- +
-=====Questions===== +
- +
-In the **incomplete/** subdirectory of the CPROG Public Directory ( **/var/public/cprog/** ), you will find a file called **tryme.cc** +
- +
-This file implements a simple class and a **main()** function. It doesn't compile in its current state. +
- +
-Please copy this file into your own **~/src/cprog/** directory, which can be done as follows: +
- +
-<cli> +
-lab46:~$ cd ~/src/cprog +
-lab46:~/src/cprog$ cp /var/public/cprog/incomplete/tryme.cc . +
-lab46:~/src/cprog$  +
-</cli> +
- +
-Read through it, and answer the following questions: +
- +
-  * What errors do you receive when trying to compile? +
-  * What is the reason the program does not compile in its original state? +
-  * How can you modify the class to fix the compilation problem (and have the program work as expected)? +
-  * Now assume you cannot modify the class, how could you fix the problem by changing code in **main()** and referencing the original class definition? +
-  * Why is it a good thing to not have direct access to the private member data of a class? Explain your reasoning. +
-  * Is there any reason you'd prefer to have direct access to all your data? If so, would the problem be better suited for a non Object-Oriented solution? Justify your answer. +
- +
-=====Program 2===== +
-Along with your responses to the above questions, please submit a working version of the **tryme.cc** program as corrected by the specifications of modifying only **main()** (leave the original class implementation intact). +
-======Review of Compiling/Executing======+
 Just to review the compilation/execution process for working with your source code, if we had a file, **hello.cc**, that we wished to compile to a binary called **hello**, we'd first want to compile the code, as follows: Just to review the compilation/execution process for working with your source code, if we had a file, **hello.cc**, that we wished to compile to a binary called **hello**, we'd first want to compile the code, as follows:
  
 <cli> <cli>
-lab46:~/src/cprog$ g++ -o hello hello.cc+lab46:~/src/cprog$ g++ -Wall --std=c99 -o hello hello.cc
 lab46:~/src/cprog$  lab46:~/src/cprog$ 
 </cli> </cli>
Line 332: Line 302:
  
 <code> <code>
-g++ -o BINARY_FILE SOURCE_FILE+g++ -Wall --std=c99 -o BINARY_FILE SOURCE_FILE
 </code> </code>
  
Line 345: Line 315:
 </cli> </cli>
  
-=====Optimization===== +=====Submission===== 
-If you find yourself experiencing "anomalous" behavior in your resulting program that just cannot be explained away (ie no discernable logic errors). You can try enabling some compiler optimizations.+To successfully complete this project, the following criteria must be met:
  
-Compiler optimizations invoke additional functionality present in the compiler that can do some alterations of your compiled code, reordering things for more efficiency, and even correcting aberrant behavior (but also having the potential to break otherwise "working" behavior).+  * Code must compile cleanly (no warnings or errors) 
 +    * Use the **-Wall** and **--std=c99** flags when compiling. 
 +  * Output must be correct, and resemble the form given in the sample output above. 
 +  * Code must be nicely and consistently indented (you may use the **indent** tool) 
 +  * Code must utilize the algorithm presented above 
 +  * Code must establish and utilize the functions described above 
 +  * Code must be commented (and those comments relevant) 
 +  * Track/version the source code in a repository 
 +  * Submit a copy of your source code to me using the **submit** tool.
  
-To use compiler optimizations, we add the "**-O#**" option (capital letter Oh) to the compiler command-line. There are a number of compiler optimizations available to us (this was all gleaned from the **gcc(1)** manual page): +To submit this program to me using the **submit** toolrun the following command at your lab46 prompt:
- +
-^  option  ^  description +
-|  -O0  |  no optimization (this is the default, it happens if you don't specify anything) +
-|  -O  |  reduce code size and execution time, plus some non-expensive optimizations +
-|  -O1  |  same as -O  | +
-|  -O2  |  optimize more. Compile time increases for the result of better code and execution +
-|  -O3  |  yet more optimizations. Long compile time, perhaps more efficient code  | +
-|  -Os  |  optimize for size. Uses a lot of -O2 optimizations so long as it does not impact code size  | +
- +
-So, if you'd like to compile your code with level 1 optimizations: +
- +
-<code> +
-g++ -O1 -o BINARY_FILE SOURCE_FILE +
-</code> +
- +
-As your programs get bigger and more complex, the utilization of compiler optimizations **can** make a significant impact on the resulting performance of your program. For most of the stuff we're doing now, you're not likely to notice many improvements. +
-======Copying files to your submit directory====== +
-As you write your code, hopefully you've developed the good habit of storing all your programs in your **~/src/cprog** directory (and have added/committed them to your repository). +
- +
-But, in order to complete your tasks, you've been requested to place it in your **~/src/submit** directory instead. +
- +
-What to do?! +
- +
-We'll simply make a **copy** of your code! Assuming we're working with a source file called **myprog.cc** in our **~/src/cprog** directorywe'll copy it into **~/src/submit/** and give it a name of: **taskX.cc** +
- +
-To do that we use the **cp** command, and run it as follows:+
  
 <cli> <cli>
-lab46:~/src/cprogcp myprog.cc ~/src/submit/taskX.cc +$ submit cprog oop0 oop0.cc 
-lab46:~/src/cprog$  +Submitting cprog project "oop0"
-</cli>+    -oop0.cc(OK)
  
-We can then hop over to our submit directory and add/commit it: +SUCCESSFULLY SUBMITTED
- +
-<cli> +
-lab46:~/src/cprog$ cd ~/src/submit +
-lab46:~/src/submit$ ls +
-contact.info    taskU.c    taskV.c    taskW.c    taskX.cc +
-lab46:~/src/submit$ svn add taskX.cc +
-Added   taskX.cc +
-lab46:~/src/submit$ svn commit -m "added taskX.cc to the submit directory" +
-...+
 </cli> </cli>
-======Submission====== 
-All questions in this assignment require an action or response. Please organize your responses into an easily readable format and submit the final results to your instructor per the appropriate methods. 
- 
-Your assignment is expected to be performed and submitted in a clear and organized fashion- messy or unorganized assignments may have points deducted. Be sure to adhere to the submission policy. 
- 
-When complete, questions requiring a response can be electronically submit using the following form: 
- 
-<html><center><a href="http://lab46.corning-cc.edu/haas/content/cprog/submit.php?task6">http://lab46.corning-cc.edu/haas/content/cprog/submit.php?task6</a></center></html> 
-\\  
- 
-Additionally, the successful results of the following actions will be considered for evaluation: 
- 
-  * placement of the code you created to solve this task in your **~/src/submit** directory 
-  * name that file: **task6.cc** 
-  * addition/commit of **task6.cc** into your repository 
-  * create a directory **task6/** in your **~/src/submit** directory 
-  * place your multi-file implementation of task6.c in this **task6/** directory 
-  * addition/commit of the **task6/** directory and all its contents to your repository 
- 
-As always, the class mailing list and class IRC channel are available for assistance, but not answers. 
  
 +You should get some sort of confirmation indicating successful submission if all went according to plan. If not, check for typos and or locational mismatches.
haas/summer2017/cprog/projects/oop0.1501594701.txt.gz · Last modified: 2017/08/01 13:38 by wedge