(1) Errors in program:

  • Missing int in main function declaration
  • Missing semicolon after the cout statement

Corrected program:

#include int main() { std::cout << "Is there a bug here?" << std::endl; }

Output: Is there a bug here?

(2) Errors in program:

  • Missing int in main function declaration
  • The station member variable in the Flower class is a bool, but it is being returned as an int in the station function
  • The m++ statement is invalid because m is an enum, not an integer

Corrected program:

#include void main() { enum Month {jan =1, feb, mar, apr, may, jun, jul ,aug, sep, oct, nov, dec}; Month m; m = feb; if( m == feb) m = static_cast(m + 1); }

(3) Errors in program:

  • The station member variable in the Flower class is a bool, but it is being returned as an int in the station function
  • The station member variable in the Flower class is not initialized

Corrected program:

#include class Flower { public: Flower() : station(false) {} int station() const {return station; } private: bool station; }; void main() { Flower rose; rose.station = true; std::cout << rose.station() << std::endl; }

Output: 1

(4) Output of program:

Input: 3 Output: a in increment 4 q in main 3

Explanation: The increment function takes in an integer by value, so a copy of q is made and stored in a. The function increments a, but this change does not affect the original value of q in main.

(5) Output of program:

Input: 1 2 3 4 Output: 4 3 2 1

Explanation: The program reads in integer numbers from the user and stores them in a vector. The swap function swaps the first element of the vector with the last element, the second element with the second-to-last element, and so on. The print function prints out the elements of the vector in reverse order

UWI C English Sample PaperSchool of Management Huazhong University of Science & Technology C++ Programming Name No Class 1 30 pointsRead about the following program and try to find out the errors

原文地址: https://www.cveoy.top/t/topic/flgZ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录