English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

The program will read the values of length and width from the user trough keyboard and passes these values to the function calculate(T x, T y). The function calculates the area and perimeter of the rectangle and displays the result on the screen. The function returns no value.

2006-07-25 19:08:22 · 2 answers · asked by moeed k 1 in Computers & Internet Programming & Design

2 answers

template< typename T>
void calculate(T x, T y) {
std::cout<< "Perimeter = "<< 2*(x+y)<< std::endl;
std::cout<< "Area = "<< x*y << std::endl;
}

int main(void) {
int x, y;
std::cin >> x >> y;
calculate(x, y);
return 0;
}

2006-07-25 19:25:49 · answer #1 · answered by swami060 3 · 0 0

quite a demand you have there :)
i haven't used C++ in a while but here is the procedure general programming syntax.

function t (Tx,Ty)
var perimeter;
var area;
perimeter = 2Tx + 2Ty;
area = Tx * Ty;
writeln("perimeter = " perimeter, "area = " area);
end function

2006-07-25 19:15:54 · answer #2 · answered by dgitts 3 · 0 0

fedest.com, questions and answers