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.
Write a C++ program that will calculate the area and perimeter of a rectangle by using the function template t
template%26lt; typename T%26gt;
void calculate(T x, T y) {
std::cout%26lt;%26lt; "Perimeter = "%26lt;%26lt; 2*(x+y)%26lt;%26lt; std::endl;
std::cout%26lt;%26lt; "Area = "%26lt;%26lt; x*y %26lt;%26lt; std::endl;
}
int main(void) {
int x, y;
std::cin %26gt;%26gt; x %26gt;%26gt; y;
calculate%26lt;int%26gt;(x, y);
return 0;
}
Reply: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
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment