constructor ?


Posted on 16th Feb 2014 07:03 pm by admin

i have written this program and made 3 constructors in the class and i want to call them in the main and i cant can any one help me and tell me how could i call them in the main

# include
using namespace std ;

class Triangle {

private :
float side1 ;
float side2 ;
float side3 ;
public :
Triangle () ;
Triangle (float , float , float ) ;
Triangle ( float[3] ) ;
float printAverage () ;
};

Triangle :: Triangle ()
{
float firstSide , secondSide , thirdSide ;

side1 = firstSide ;
side2 = secondSide ;
side3 = thirdSide ;
}

Triangle :: Triangle ( float firstSide , float secondSide , float thirdSide )
{
side1 = firstSide ;
side2 = secondSide ;
side3 = thirdSide ;
}

Triangle :: Triangle ( float side[3] )
{
side1 = side[0] ;
side2 = side[1] ;
side3 = side[2] ;
}

float Triangle::printAverage ()
{
return ( side1 + side2 + side3 ) / 3 ;
}

int main ()
{
float firstSide , secondSide , thirdSide ;

cout << "Enter First Side : " ;
cin >> firstSide ;
cout << "Enter Second Side : " ;
cin >> secondSide ;
cout << "Enter Third Side : " ;
cin >> thirdSide ;

Triangle tri1 = Triangle () ;
Triangle tri2 = Triangle () ;
Triangle tri3 = Triangle () ;


system("pause");
return 0;

}

No comments posted yet

Your Answer:

Login to answer
88 Like 49 Dislike
Previous forums Next forums
Other forums

Display error above the login forum help!
Hi guys. just so you know im not asking for someone to do this for me I just need to be pointed in t

Ten Operator Syntax
Hi Guys,

I can't figure out why i am getting a parse error with this basic ten op code:

how to easy edit text, with box? Help.
Hi.
I have a little problem. I'm doing a webpage for my aunt and I would like to make it as easy

Changes to hosting company's server has affected web contact form
I started a thread a couple of months ago about the contact forms on my client's website. Basically

Javascript form submit and radio buttons?
When this form is submitted, it is automatically resubmitted using JS.

All my fields are carr

How to write on database when a link is clicked?
Hi, I have a list of products in a gridview. When the link is clicked currently it takes to an ext

recrawling
Can anyone suggest me how may i know a page is updated before it is being downloaded, so that i can

PHP time (deadline within one week)
I have a column ['projdue'], which stores the deadline for a project.
I have PHP code and <

Something Non-Traditional. Can we solve?
I have an idea for an application here. It's mostly flash, but it couldn't work without a somewhat n

Timer control causing error
I recently decided to add a timer control to an existing page that uses AJAX on my site. As soon as

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash