Finding the 2 Largest Values from 3 Inputs

  • Thread starter Thread starter taxi
  • Start date Start date
Click For Summary
SUMMARY

The discussion focuses on creating a program using the Little Man Computer (LMC) model to identify the two largest values from three inputs. A user seeks assistance in extending their knowledge from finding the largest of two values to three. A solution is provided in C++ with a function named max that determines the largest of three double values, demonstrating the logic needed to derive the two largest values subsequently. The conversation emphasizes the importance of understanding function implementation and operator overloading for more complex data types.

PREREQUISITES
  • Understanding of the Little Man Computer (LMC) model
  • Basic knowledge of C++ programming
  • Familiarity with function creation and return values in C++
  • Concept of operator overloading in C++
NEXT STEPS
  • Research how to implement the Little Man Computer (LMC) model in programming
  • Learn about C++ function overloading and its applications
  • Explore algorithms for finding the largest values in arrays or lists
  • Study operator overloading in C++ for custom classes
USEFUL FOR

Programmers, computer science students, and educators interested in algorithm development, particularly those working with C++ and the Little Man Computer model.

taxi
Messages
2
Reaction score
0
hi.

i'm trying to make an lmc that gives oupts the 2 largest values from 3 inputs.

i know how to find out the largest from 2 values but can't think of how to get the largest from 3 inputs.

any help would be appreciated

thanks
 
Technology news on Phys.org
I have no idea what an "lmc" program is. Could you elaborate on that?

Regardless, returning the largest pair of three given values is trivial. I'll give you a hint how to write a function that will return the largest single value from three values; writing a function to return the largest two values should then be easy for you. I'll write it in C++ for the sake of argument.

Code:
double max(const double& a, const double& b, const double&c)
{
   double maxTempVariable = a;

   if (b > maxTempVariable)
      maxTempVariable = b;
   if (c > maxTempVariable)
      maxTempVariable = c;

   return maxTempVariable;
}

If you're interested in applying this to more general objects, classes together with appropriately overloaded relational operators is the ways to go.
 
shoehorn said:
I have no idea what an "lmc" program is. Could you elaborate on that?

Regardless, returning the largest pair of three given values is trivial. I'll give you a hint how to write a function that will return the largest single value from three values; writing a function to return the largest two values should then be easy for you. I'll write it in C++ for the sake of argument.

Code:
double max(const double& a, const double& b, const double&c)
{
   double maxTempVariable = a;

   if (b > maxTempVariable)
      maxTempVariable = b;
   if (c > maxTempVariable)
      maxTempVariable = c;

   return maxTempVariable;
}

If you're interested in applying this to more general objects, classes together with appropriately overloaded relational operators is the ways to go.

have a look at this.

http://en.wikipedia.org/wiki/Little_man_computer
 

Similar threads

  • · Replies 29 ·
Replies
29
Views
4K
Replies
1
Views
3K
Replies
17
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 28 ·
Replies
28
Views
6K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 14 ·
Replies
14
Views
3K