Guest User

Untitled

a guest
Apr 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.89 KB | None | 0 0
  1. // Course: CS 1410 Section X01
  2. // Instructor: Prof Debry
  3. // Student: Ramsey Lawson
  4. // Contents: Project 11
  5. // Date: November 21 2011
  6. // I declare that the following source code was written solely by me, or provided by the
  7. // instructor. I understand that copying any source code, in whole or in part, constitutes
  8. // cheating, and that I will receive a zero in this assignment if I am found in violation of
  9. // this policy.
  10.  
  11. #include <iostream>
  12. #include <string>
  13. #include <vector>
  14. #include "rectangle.h"
  15. using namespace std;
  16.  
  17. // declare global constants here
  18. const int MAX_SIZE = 3;
  19.  
  20. // declare functions here
  21. void prologue();
  22. void printRectangle(const rectangle&);
  23.  
  24. int main( )
  25. {
  26.     // declare local variables here
  27.     rectangle userDefinedRectangle;
  28.     string places[MAX_SIZE] = { "1st", "2nd", "3rd" };
  29.     int userInput = 0;
  30.     vector<rectangle> rectangles(MAX_SIZE); // vector to hold rectangle objects
  31.     // int index = 0;
  32.  
  33.     // C++ statements
  34.     prologue();
  35.    
  36.     // Prompt the user to enter in the dimensions of three Rectangles.
  37.     for (int i = 0; i < MAX_SIZE; i++)
  38.     {
  39.         cout << "\nPlease type the dimensions of the " << places[i] << " rectangle" << endl;
  40.         cout << "Height = ";
  41.  
  42.         cin >> userInput;
  43.  
  44.         userDefinedRectangle.setHeight(userInput);
  45.  
  46.         cout << "Width = ";
  47.  
  48.         cin >> userInput;
  49.  
  50.         userDefinedRectangle.setWidth(userInput);
  51.  
  52.         rectangles[i] = userDefinedRectangle;
  53.  
  54.     } // end data gathering loop
  55.    
  56.     // Using the data provided by the user create three Rectangle objects.
  57.  
  58.     const int SEPARATOR = 44;
  59.     for (int i = 0; i < SEPARATOR; i++)
  60.         cout << "-";
  61.     cout << endl;
  62.  
  63.     // For each Rectangle object that you created call the stand-alone function printRectangle.
  64.  
  65.     printRectangle(userDefinedRectangle);
  66.  
  67.     system("PAUSE");
  68.     return 0;
  69. } // end main
  70.  
  71. // Function Name: printRectangle
  72. // Purpose: prints rectangle properties
  73. // Parameters: reference to a Rectangle object
  74. // Returns: none
  75. void printRectangle(const rectangle &shape) // (const vector<rectangle> &shape) vs (const rectangle &shape)
  76. {
  77.     /*
  78.     for (int i = 0; i < MAX_SIZE; i++)
  79.         cout
  80.  
  81.         */
  82.  
  83.     cout << "\nRectangle " << endl;
  84.    
  85.     // The rectangle's height
  86.     cout << "width = " << shape.getHeight() << endl;
  87.  
  88.     // The rectangle's width
  89.     cout << "height = " << shape.getWidth() << endl;
  90.  
  91.     // The rectangle's area
  92.     cout << "Area = " << shape.calcArea() << endl;
  93.  
  94.     // The rectangle's perimeter
  95.     cout << "Perimeter = " << shape.calcPerimeter() << endl;
  96.  
  97.     // Whether or not the rectangle is also a square.
  98.     if (shape.isSquare() == true)
  99.         cout << "This rectangle is also a square." << endl;
  100.  
  101. } // end printRectangle function
  102.  
  103. // Prologue Function
  104. // Purpose: Program prints out your name, section, and the text "Project/Lab XX"
  105. // Parameters: none
  106. // Returns: none
  107. void prologue()
  108. {
  109.     string assignment = "Project 11";
  110.    
  111.     cout << "Ramsey Lawson\nSection X01\n" << assignment << endl;
  112. } // end prologue function
Add Comment
Please, Sign In to add comment