1 and 2: Write a function RectArea that takes in lengths (double) of a rectangle and returns the area (double) + overload RectArea to take ints in place of doubles
3. ) Write a driver (main) that uses the file from question 1 & 2 (prototype with extern). The program should
take in the values from command line (./main one two) and prints the area in the driver program (File=main1.cpp).
Hello, I am trying to teach myself C++ and I came across these problems on the Internet. I was able to 1 and 2, but I am not quite sure about how to do 3.
My guess is that you have to make a new program, and in this new program, you put #include <iostream> and #include rectArea.cpp (That's the file of question 1 and 2) and using namespace std;
Am I right?????
Also, the problem said something about extern. What should I do with extern prototypes????
If this is the case, what do you do after using namespace std;?
Here's what I have so far
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
#include <iostream>
using namespace std;
double rectArea(double, double);
int rectArea(int, int);
int main ()
{
double length;
double width;
cout << "What is the length of the rectangle? " << endl;
cin >> length;
cout << "What is the width of the retangle? " << endl;
cin >> width;
rectArea(length, width);
return 0;
}
double rectArea(double l, double w)
{
double area;
area = l * w;
return area;
}
int rectArea(int l, int w)
{
int area;
area = l * w;
return area;
}
|