| | |
Use of Template in C++, needs help
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2006
Posts: 1
Reputation:
Solved Threads: 0
I am new in C++, and learning the langauge by my self only, while practicing i come across one question for which i have no idea, the question is to calculate area and perimeter of rectangle, the code i wrote was
BUT I WHAT I NEED IS
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.
Can someone HELP?
thankx
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; int main () { // declaration of variables float length; //length of a rectangle float width; //width of a rectangle float area; //area of a rectangle float perim; //perimeter of a rectangle // prompt for and read the input values cout << "Enter the length of the rectangle" << endl; cin >> length; cout << "Enter the width of the rectangle" << endl; cin >> width; //Calculate the area and the perimeter area = length*width; perim = 2.0*length + 2.0*width; //Display the result cout << "The area is " << area << endl; cout << "The perimeter is " << perim << endl; return 0; }
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.
Can someone HELP?
thankx
Last edited by WolfPack; Jul 26th, 2006 at 2:56 pm.
Maybe this can give a rough idea on how a function is organized
and this can be called in main using
Hope it helped,
Bye.
C++ Syntax (Toggle Plain Text)
float calculateArea (float length, float breadth) { return (length * breadth); } float calculatePerimeter (float length, float breadth) { return (2 * length + 2 * breadth); }
and this can be called in main using
C++ Syntax (Toggle Plain Text)
cout << "THe area of reactangle is " << calcuateArea (length, width); cout << "THe perimeter of reactangle is " << calcuatePerimeter (length, width);
Hope it helped,
Bye.
I don't accept change; I don't deserve to live.
![]() |
Similar Threads
- Invalid add-in template (Windows NT / 2000 / XP)
- Using CMSs for one's Design Template (Existing Scripts)
- PHP .tpl format template help! URGENT! (PHP)
- Which template is it? [vbulletin] (PHP)
- Smart client template solution ??? (ASP.NET)
- vb trainer template (Visual Basic 4 / 5 / 6)
- Using a Folder Type as a Template (Windows tips 'n' tweaks)
Other Threads in the C++ Forum
- Previous Thread: is learn C++ in 24 hours good?
- Next Thread: Help With Pointer Stack
| Thread Tools | Search this Thread |
api array arrays based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






