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

How to submit a form to the same page?
I have a table containing information about books in my library and this table has the following col

Variables and Include
Code: [Select]<?php

$header = $_COOKIE['mss']['header'];
$body = $_COOKIE['mss']['b

asking for direction
I have 2 tables in my data, which are "post" and "event"
I won't make a summa

issues verifying if user is logged in
I am having issues when a user logs in via asp Login control, the IsAuthenticated still seems to com

double and single quotes in text fields acting up... help please
Single quotes, when entered into a text field, create an sql error upon Submit. It seems to create t

Hardcopy printing is to wide
I want to make a hardcopy at runtime of my active form like this

How to search for several parameters from objects in a database?
I have a database with lots of information about objects.
Now I would like to search for 4 or 5 p

Finding digits in variable containing text, and IDing them
$romanstock = "http://www.remoteprice.com/data.asp?storeid=123&itemcode=456&typ

How to convert this array to string
I am having problems converting this array to a string
using print_r($val[1]); I get:
Code: [

start new row of pictures
on my site www.budstreasureauctions.com there is a featured auctions box that users will pay to get

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