Q:

Write your own versions of the fact.cc and factMain.cc files. These files should include your Chapter6.h from the exercises in the previous section. Use these files to understand how your compiler supports separate compilation

0

Write your own versions of the fact.cc and factMain.cc files. These files should include your Chapter6.h from the exercises in the previous section. Use these files to understand how your compiler supports separate compilation.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

"Chapter6.h"

// For ex6.9
#ifndef CHAPTER_6_H
#define CHAPTER_6_H

int fact(int);

#endif

"fact.cc"

#include "Chapter6.h"

int fact(int n) {  // Ignore overflow
  if (n < 1) return n;
  int k = n;
  while (--n)
    k *= n;
  return k;
}

 factMain.cc

#include <iostream>
#include "Chapter6.h"

int main() {
  int n;
  while (std::cin >> n)
    std::cout << n << "! = " << fact(n) << std::endl;

  return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now