Post-lab - Lab (7)


Before continuing, answer the following questions.  

1. What are the three main types of files that you will be using when you create C++ programs?

2. What the g++ flags -c and -o do? Give an example of how they are used.

 

Using the source code from Ch 4 Ex. 4.15 from the text website (or CD) (Program listing in the text of 4.15) for factorial, create three files:

factorial.hpp

factorial.cpp

driver.cpp

Inside of factorial.hpp and factorial.cpp, put the appropriate code for the declaration and definition of the factorial code. Be sure to use good programming pratices (header comments, good variable names, formatting, etc.). Create a Makefile for the program compilation by modifying the Makefile of the exercise 7.3. Use gbd to debug your program.

Copy the following code for the driver.cpp program. Be sure to test your code and make sure it works with this driver.

/* driver.cpp - factorial driver program */
#include <iostream>
#include "factorial.hpp"


using namespace std;


int main(void)
{
	int n, f, choice = 1;
	while (choice == 1)
	{

		cout << "Enter the value you want the factorial of: ";
		cin  >> n;
		f = factorial(n);
		cout << "The factorial of " << n << " is " << f << endl;
		cout << "\nDo you want to continue?  (1 for Yes, 0 for No): ";
		cin  >> choice;  

	} // end of while (choice == 1) loop
	return 0;

}

Instructions to return your lab to the teacher: (5 points penalty if instructions are not followed appropriately)

  1. Be sure you return the pre-lab where you have written all your answers.
  2. Transfer ONLY the source files you have written from loki to your local Windows machine and collect them in a  folder called YourLastNameLab7 (ex. AGuercioLab7). Be sure you did not copy any executable file in this folder. If you did, please remove it from the folder.
    The files to be zipped are:

    Exercise 7.2: sum and average  
    average.hpp (with both sum and average declarations)
    average.cpp (both sum and average definitions)
    avg_driver.cpp

    Post Lab: (Worth 50% of score)
    factorial.h
    factorial.cpp
    driver.cpp
    Makefile (make sure it is for the factorial and NOT the average code)

    DO NOT INCLUDE: Exercise 7.1 or 7.3:


  3. Now exit from the folder, right click on the folder and choose WinZip--> Zip and e-mail. This action will pack your folder and attach it to an e-mail. You can use a Rar Program if you have that program instead of the Zip program.
  4. Send the e-mail to kschaffe@kent.edu with the subject CS23021 Lab 7 Submission.
  5. Send your e-mail before the deadline to receive full credit.

Congratulations! You have completed another Lab of CS I !! :-))