C++
C++/C Computer Programming Language Middle Examination
1. (10%)Please state the features of C++ Programming Language
2. (5%) A comment is text that the compiler ignores. How to write a C++ comment to annotate code?
(Hint: A C++ comment may be written in two ways)
3. (20%)
(A): What is the difference between “call function by value” and “call function by reference?
(B): What is the difference between regular variable and “const” variable?
(C): What is the difference between local variable and global variable?
(D): How the c++ limit the scope of variable?
4. (5%)What are the capabilities of the following objects? What header file should you include first if you want to use them? (Hint: #include<iostream>, #include<fstream>, #incdlue<vector>)
(A): std::cout
(B): std::cin
(C): std::ifstream
(D): std::ofstream
(E): std::vector
5. (5%)Indicate the errors of the following program and correct them.
#include <fstream>
int main ()
{
for (int k=0, k<10, k++)
std::cout << k <<std::endl;
return 0;
}
6. (10%) Write the results (outputs) of the following program.
#include <iostream>
int main ()
{
int a =2 , b = 3, c = 5;
double x = 2.0, y = 3.0, z= 5.0;
/* 6.1 */ std::cout << c/a <<std::endl;
/* 6.2 */ std::cout << z/a <<std::endl;
/* 6.3 */ std::cout << z/x <<std::endl;
/* 6.4 */ std::cout << c%b <<std::endl;
/* 6.5 */ std::cout << ((a<b) ? x : y) <<std::endl;
/* 6.6 */ std::cout << a++ <<std::endl;
/* 6.7 */ std::cout << ++a <<std::endl;
/* 6.8 */ std::cout << ((a<b) ? x : y) <<std::endl;
/* 6.9 */ for ( b = 0 ; b < 3 ; b++)
std::cout << a * b << std::endl;
return 0;
@上機--- Finish the following three programs using a personal computer.
7. (5%)
Complete the following function so that it will return the sum of all elements in the argument (std::vector<double> )
double CalSum (std::vector<double> dArg)
{
double sum = 0.0;
for( __________________)
{
sum += dArg[i];
}
return sum;
}
8. (10%) Write a program that it writes the following data to the file “md1.dat”. The fragment must fill with your team number.
The number of our team is ___
The output data
100
200
300
400
500
9. (30%)
(A) Write a c++ program that can randomly generates two 5x5 matrixes and then writes these two matrix into data file “md2.dat”
(B) Complete the following three functions so that it will return the sum, difference, and multiple of two matrixes, Matrix A and Matrix B. These two matrixes must be declared using std::vector< std::vector<double>>. For instance, the function definition could be as follow:
std::vector<std::vector<double >>
CalMatSum (std::vector<std::vector<double>> A, std::vector<std::vector<double>> B)
std::vector<std::vector<double >>
CalMatDiff (std::vector<std::vector<double>> A, std::vector<std::vector<double>> B)
std::vector<std::vector<double >>
CalMatTime (std::vector<std::vector<double>> A, std::vector<std::vector<double>> B)
(C) Write a main function that
i. Reads these two matrixes from md2.dat
ii. Call these three functions, CalMatSum(), CalMatDiff(), CalMatTime() to calculate the sum, difference, and multiple of these two matrixes.
iii. Write the produces of the main functions into md3.dat
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.168.72.167
推
03/28 18:12, , 1F
03/28 18:12, 1F
推
03/28 21:22, , 2F
03/28 21:22, 2F
→
03/29 21:26, , 3F
03/29 21:26, 3F
→
03/29 21:28, , 4F
03/29 21:28, 4F
推
03/29 22:03, , 5F
03/29 22:03, 5F
推
03/29 22:04, , 6F
03/29 22:04, 6F
推
03/30 12:08, , 7F
03/30 12:08, 7F
→
03/30 12:08, , 8F
03/30 12:08, 8F
→
03/30 14:56, , 9F
03/30 14:56, 9F
→
03/30 14:59, , 10F
03/30 14:59, 10F
討論串 (同標題文章)