C++代写|CS 代写

CS-UY 2124 Object Oriented Programming

 

What to do:

Design a C++ class to manage measurements. The class should have two integer data members: feet and inches. It must ensure that the inches attribute remains within the range of 0 to 11, adjusting the feet attribute accordingly if necessary. This implies that feet might become negative.

Implement two constructors for the class:
1. A default constructor that initializes both `feet` and `inches` to zero.

2. A constructor that takes one integer argument representing the total number of inches.

Ensure that the class handles conversions between feet and inches appropriately and maintains 
the constraints specified above.

Additionally, in the main function, after creating instances of the class using both constructors, test the setter method for feet by setting it to a negative value and displaying the updated measurements.


Good Code

Writing good code means that your program needs:

Good comments. Every program file should have a comment at the top to identify the file, the author and, briefly, the purpose of the code in the file. Every function definition should have a comment identifying its purpose, the purpose of its parameters and that of its return value. Unlike Python docstrings, this comment comes just before the function. Any block of code, e.g. loop, should have a comment to explain enough of what it does so that the reader could skip reading the code in that block altogether without missing anything.

Good functions. Well, we addressed that above in the requirements. Normally, thinking of good functions is a key part of your task. You are welcome to add any functions you think would be helpful here!

Function prototypes. 
Function prototypes come before main. Function definitions should come after main. If you haven't covered function prototypes, don't worry, it will only take you a few minutes to add them to your program.


Good naming
. Both variables and functions should have good names. A function's name should say clearly what it does.
A variable's name should say clearly what it holds. No,
not its type but what its purpose is in the application. Calling a vector of strings something like "stringVec" would be silly at best. If the vector is holding the lines from a file, perhaps it might be called "lines". In general, single letter names are unacceptable. Yes, we do often use the letters i and j as loop index variables, at least if the loop is reasonably short and their scope is limited by the loop itself. Even then, a more meaningful name helps clarify at a glance the intent of the code. An index variable called row might work better in some cases. Similarly, variables with names like temp don't help the reader and should (almost) never be used.