Introduction to NetEase Cloud classroom _c++ Programming (top) _ 4th unit: Birds of a feather-objects and Classes-Unit 4th Job "1"-Online programming (difficulty: Easy)

Source: Internet
Author: User

1

Consider creating a drawing program. You need a screen that is used to represent a drawing when the screen has some basic properties, such as width and height, and some basic operations, such as capturing the width and height of the screen (10 points)

Topic content:

1. The screen class has two private int data members representing both the width and height

2. The screen class has two constructors

      1. There are two integer parameters, each of which is the width and height of the screen (in pixels)

      2. The parameter constructor stores the width and height of the screen in the private data field of the class.

        The parameter constructor of the screen class

        The default constructor for the screen class sets the width and height to 640 and 480, respectively.

      3. All constructors of the screen class should output the string "screen" and wrap it.

      4. Line breaks in code need to use Cout::endl

3. Provide getter and setter functions for private data members and, if necessary, add additional data members and function members. Function prototypes are as follows

    1. int getwidth ();
    2. int getheight ();
    3. int setwidth (int width); //return width
    4. int setheight (int height); //return height

4. The main function used by the code is as follows (no changes should be made):

  1. int Main () {
  2. int width, height;
  3. std::cin >> width >> height;
  4. Screen screen1 (width, height);
  5. Screen screen2;
  6. Screen2.setwidth (+);
  7. Screen2.setheight (+);
  8. std::cout << screen1.getwidth () << " << screen1.getheight () << Std::endl;
  9. std::cout << screen2.getwidth () << ' << screen2.getheight ();
  10. #ifdef DEBUG
  11. std::cin.get ();
  12. #endif
  13. return 0;
  14. }

Input format:

Two integers separated by spaces, representing the width and height of the screen

Output format:

Two calls to the constructor output string, string wrapping

Two different screen objects wide and high, separated by spaces, the width and height of the first screen object and the line wrapping after the output

Input Sample:

320 240

Sample output:

Screen

Screen

320 240

800 600

Note : The above output is 4 lines and there is no line break after the last line

time limit: 500ms memory limit: 32000kb 
#include <iostream>class screen{public:int getwidth (); int getheight (); int setwidth (int width);  return widthint setheight (int height); return heightpublic:screen (int width, int height);//Parameter constructor screen ();//default constructor private:int width;//width int height;// The high};int of the screen Screen::getwidth () {return width;} int Screen::getheight () {return height;} int screen::setwidth (int width)//return width{this->width = Width;return width;} int screen::setheight (int height)//return height{this->height = height;return height;} Screen::screen (int width, int height)//parameter constructor {std::cout << "screen" << std::endl;this->width = width; This->height = height;} Screen::screen ()//default constructor {std::cout << "screen" << std::endl;this->width = 640;this->height = 480;} int main () {int width, height;std::cin >> width >> height; Screen screen1 (width, height); Screen Screen2;screen2.setwidth (screen2.setheight); Std::cout << screen1.getwidth () << "< < SCReen1.getheight () << std::endl;std::cout << screen2.getwidth () << ' << screen2.getheight (); Ifdef debugstd::cin.get (); #endifreturn 0;}

Introduction to NetEase Cloud classroom _c++ Programming (top) _ 4th unit: Birds of a feather-objects and Classes-Unit 4th Job "1"-Online programming (difficulty: Easy)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.