C++代写:CS1 Practice Basic C++

回顾之前学的基础C++的特性,如class, function, object state等,完成下述作业。

Assignment Goal

Goal of this assignment is to help you practice basic C++ constructs such as classes, functions, object state, arrays, etc., and get you started with C++ programming. You can use any editor, development environment, but your final submission must compile and run on the CS1 server (cs1.seattleu.edu).

NOTE: If you need a quick refresher on classes in C++, refer http://www.cplusplus.com/doc/tutorial/classes/

Write definition for a Rectangle class that has integer data member length and width, and the following member functions:

  1. void setlength(int) to set the length data member
  2. void setwidth(int) to set the width data member
  3. int perimeter() to calculate and return the perimeter of the rectangle
  4. int area() to calculate and return the area of the rectangle
  5. void show() to display the length and width of the rectangle
  6. int sameArea(Rectangle) that has one parameter of type Rectangle. This function returns 1 if the two Rectangles have the same area, and returns 0 if they don’t.
  7. Include a parameterized constructor Rectangle(int length, int width), which sets the length and width of the rectangle to specified values.
  8. Also include a default constructor Rectangle(), which sets length, and width to 0 by default.

Expected program behavior

When executed, your program should do the following (roughly) in the indicated sequence:

  1. Create an array to store five rectangle objects.
  2. Ask user to enter the length and width of the five rectangles one by one.
  3. Initialize the length and width of the five rectangles in the array with values entered in step 2.
  4. For each of the five rectangles, print their length, width, area, and perimeter one by one over five lines. For example: Rectangle 0: len = 10, width = 20, area = 200, perimeter = 60. Make sure the o/p is easy to read.
  5. Print the same information as in step 4, but only for the rectangle with smallest area. The information should be preceded by label saying “Rectangle with smallest area: “
  6. Print the same information as in step 4, but only for the rectangle with largest area. The information should be preceded by label saying “Rectangle with largest area: “
  7. Print the same information as in step 4, but only for the rectangle with smallest perimeter. The information should be preceded by label saying “Rectangle with smallest perimeter: “
  8. Print the same information as in step 4, but only for the rectangle with largest perimeter. The information should be preceded by label saying “Rectangle with largest perimeter: “
  9. If there are two or more rectangles with same area, print them here. For example, if area of rectangles were: r0=20, r1=30, r2=10, r3=20, r4=50, print “Rectangles r0, r3 have equal areas of 20 units each.” If none of the rectangles have equal areas, simply say “No rectangles with equal area found.
  10. If there are two or more rectangles with same perimeter, print them here. For example, if perimeter of rectangles were: r0=20, r1=30, r2=10, r3=20, r4=50, print “Rectangles r0, r3 have equal perimeters of 20 units each.” If none of the rectangles have equal perimeters, simply say “No rectangles with equal perimeter found.
  11. Prepare a “README.txt” file for your submission. The file should contain the following:
    • I. Instructions for compiling and executing your program(s). Include an example command line for the same.
    • II. If your implementation does not work, you should also document the problems in the README file, preferably with your explanation of why it does not work and how you would solve it if you had more time.

Notes

  1. Your program should provide the requested functionality and member functions. If not, a penalty of up to 20% will be imposed on your final score.
  2. The output of your program should be readable, and self-explanatory.
  3. Appropriately document your program (see design and documentation guidelines in ProgrammingGuidelines.pdf)
  4. Use C++ constructs as intended
  5. You may NOT use STL (Standard Template Library).
  6. You should also comment your code well. The best way to go about it is to write comments while coding. If your code is not well structured and documented/commented, a penalty of up to 20% will be imposed on your final score.
  7. Your submission should compile and run on CS1 server.
  8. Programs that fail to compile on CS1 will receive a zero.
  • ALL ASSUMPTIONS SHOULD BE REASONABLE AND CLEARLY STATED
  • DO NOT HARD CODE
  • TEST YOUR PROGRAM BEFORE SUBMISSION

What should you submit?

Upload your submission as a zip file on Canvas. The zip file should contain:

  1. All your code files and any other files that might be needed for executing your code.
  2. README.txt.