Jump to content
  • Advertisement
Sign in to follow this  
  • entries
    292
  • comments
    557
  • views
    154547

Overly Convoluted Homework Programs.

Sign in to follow this  
TANSTAAFL

86 views

If you've ever taken a look at the public board on Kasamba, you've seen lots of homework questions. I found one, and decided to make an overly complex solution to a rather simple problem. However, the guy yanked his question before I got a chance to post it, so here it is:

#include
#include

template
class triangle_area_calculator
{
private:
client_t a,b,c;
public:
triangle_area_calculator(client_t a,client_t b,client_t c){this->a=a;this->b=b;this->c=c;}
bool is_triangle(){client_t s=(a+b+c)/2;return(((s-a)*(s-b)*(s-c))>0);}
client_t get_area(){client_t s=(a+b+c)/2;return(sqrt(s*(s-a)*(s-b)*(s-c)));}
};

int main(int argc,char* argv[])
{
std::cout<<"Calculate an area of a triangle from its three sides."< std::cout<<"Please enter the three lengths, separated by spaces."< double a,b,c;
std::cin>>a>>b>>c;
std::cout< triangle_area_calculator calculator(a,b,c);
if(calculator.is_triangle())
{
std::cout<<"The area of the triangle is "< }
else
{
std::cout<<"Those are not valid lengths for the three sides of a triangle."< }
return(0);
}
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!