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
(1) Errors in program:
- Missing int in main function declaration
- Missing semicolon after the cout statement
Corrected program:
#include
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
(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
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
原文地址: https://www.cveoy.top/t/topic/flgZ 著作权归作者所有。请勿转载和采集!