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 36 37 38 39 40 41 42 43 44 45 46 47
|
//main.cpp
#include <iostream> //note you need a #
using std::cout;
using std::cin; //using standard namespace cin and cout.. In this case it's the same as using namespace std
void extern input (float&, float&);
void extern output (float length, float width, float area, float perimeter);
void extern calculate (float length, float width, float & area, float & perimeter);
int main () {
// Declaration (data)
float length, width;
float area, perimeter;
// Logic (executable)
input(length, width);
calculate (length, width, area, perimeter);
output (length, width, area, perimeter);
getchar(); //this is better then system("pause")
return 0;
}
void input (float & length, float & width)
{
cout << "Enter length and width of rectangle seperated by a space-> ";
cin >> length >> width;
}
void calculate (float length, float width, float & area, float & perimeter)
{
//executable coding - logic - algorithm
area = length * width; perimeter = (length + width) * 2;
}
void output (float length, float width, float area, float perimeter)
{
cout <<"the length is " << length << "\n"; cout <<"the width is " << width << "\n"; //note that there's a \n instead of endl, since \n is faster, and in this case does the same
cout <<"The area is " << area << "\n"; cout <<"The perimeter is " << perimeter << "\n";
}
|