-
April 23rd, 2017, 11:12 AM
#16
Re: I need help with writing a program in C++ (I'm still a newbie)
Originally Posted by lebro98
Thanks for all the replies! It really helped me. But last thing and I won't bother you anymore, may somebody please tell me what to do in the main() function, because I really have no idea.
For the posted code
Code:
Triangle t1;
face();
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
April 23rd, 2017, 11:15 AM
#17
Re: I need help with writing a program in C++ (I'm still a newbie)
As I'm feeling in a good mood and you're tried first, consider
Code:
#include <iostream>
#include <cmath>
using namespace std;
class Triangle
{
public:
Triangle(int aa, int bb, int cc) : a(aa), b(bb), c(cc) {}
double face()
{
double p = (a + b + c) / 2.0;
return sqrt(p*(p - a)*(p - b)*(p - c));
}
bool isTriangle()
{
return (a + b > c && a + c > b && b + c > a);
}
private:
int a, b, c;
};
int main()
{
int a, b, c;
cout << "Enter the 3 sides of the triangle as integers: ";
cin >> a >> b >> c;
Triangle t1(a, b, c);
if (t1.isTriangle()) {
cout << "Is a triangle" << endl;
cout << "The face is " << t1.face() << endl;
} else
cout << "Is not a triangle" << endl;
return 0;
}
Happy coding
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
April 23rd, 2017, 11:24 AM
#18
Re: I need help with writing a program in C++ (I'm still a newbie)
Thank you so much!!! I really am exhausted. I have to do this and 2 websites due tomorrow and have been dealing with this for 2-3 hours (I wasn't even close to what you wrote)
-
April 23rd, 2017, 11:45 AM
#19
Re: I need help with writing a program in C++ (I'm still a newbie)
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|