Home > Net >  C #
C #

Time:09-27

Written in c # constructor and class program calculated triangle area, consult, write several hours, the old display error

CodePudding user response:

Post code

CodePudding user response:

reference 1st floor Bridge_go response:
post code

Using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

The namespace ConsoleApplication1
{
Class Program
{
The static void Main (string [] args)
{
Console. WriteLine (" the length of three sides respectively: ");
The length of the Console. WriteLine (" a ");
Double a=double. Parse (Console. ReadLine ());
The length of the Console. WriteLine (" b ");
Double b=double. Parse (Console. ReadLine ());
The length of the Console. WriteLine (" c ");
Double c=double. Parse (Console. ReadLine ());
Double momo=among the no1 (a, b, c);
Console. WriteLine (" the area of the triangle {0} : ", momo);
The Console. ReadKey ();
}
Public class among
{
Public static double no1 (double a, b double, double c)
{
If (a + b & gt; C & amp; & A + c & gt; B & amp; & B + c & gt; A)
{
Double s;
Double area;

S=(a + b + c)/2;
Area=math.h Sqrt (s * (s - a) * (s - b) * (s - c));

return s;
}
The else
{
Console. WriteLine (" error!" );
return 0;
}
}
}
}
}

CodePudding user response:

The teacher let to the constructor

CodePudding user response:

Then you can create a constructor,
Public among (a, b, c)

Then the method to no1 (), don't need parameters,

No1 in the parameters of the call, from the constructor parameters

CodePudding user response:

refer to 4th floor are nu month god reply:
then you can create a constructor,
Public among (a, b, c)

Then the method to no1 (), don't need parameters,

Call parameters in no1, came from the parameters of the constructor provides

This constructor I won't use

CodePudding user response:

refer to fifth floor ╰ Angel, floating city ゛ response:
Quote: refer to 4th floor are nu month god reply:
then you can create a constructor,
Public among (a, b, c)

Then the method to no1 (), don't need parameters,

Call parameters in no1, came from the parameters of the constructor provides

This constructor I won't use

The foundation of baidu check, very simple

CodePudding user response:

There is no constructor, you is only one way

CodePudding user response:

https://docs.microsoft.com/zh-cn/previous-versions/visualstudio/visual-studio-2010/0b0thckt (v=vs. 100)? Redirectedfrom=MSDN

CodePudding user response:

Well, thank you, I try again

CodePudding user response:

I know this is is, but can't write to the main method

CodePudding user response:

references to the tenth floor ╰ Angel, floating city ゛ response:
I know this is is, but the main method to write not

Are you sure this is wrong, what is your mistake, you can use 2 l code, didn't write constructor will be the default constructor is empty a no-parameter constructor

CodePudding user response:

references to the tenth floor ╰ Angel, floating city ゛ response:
I know this is is, but the main method to write not
sorry didn't look at the topic to say to want to into a constructor

CodePudding user response:

But the teacher had to change,,,, didn't understand what to change,

CodePudding user response:

 
Class Program
{
The static void Main (string [] args)
{

Console. WriteLine (" the length of three sides respectively: ");
The length of the Console. WriteLine (" a ");
Double a=double. Parse (Console. ReadLine ());
The length of the Console. WriteLine (" b ");
Double b=double. Parse (Console. ReadLine ());
The length of the Console. WriteLine (" c ");
Double c=double. Parse (Console. ReadLine ());
Double area=new Triangle (a, b, c). GetArea ();
Console. WriteLine (" the area of the triangle {0} : ", area);

Console.ReadLine();
}
}

Public class Triangle
{
Public double SideA {get; The set; }
Public double SideB {get; The set; }
Public double SideC {get; The set; }
Public Triangle () {}

Public Triangle (double sideA, double sideB, double sideC)
{
SideA=SideA;
SideB=SideB;
SideC=SideC;
}

Public double GetArea ()
{
If (SideA + SideB & gt; SideC & amp; & SideA + SideC & gt; SideB & amp; & SideB + SideC & gt; SideA)
{
Double s;
Double area;
S=(SideA + + SideC SideB)/2;
Area=math.h Sqrt (s * (s - SideA) * (s - SideB) * (s - SideC));
return s;
}
The else
{
Console. WriteLine (" error!" );
return 0;
}
}
}

CodePudding user response:

Using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • C#