c++编程改错~~
1. Before you enter the following program in the computer, please point out the errors of it, then analyze and correct the errors.#include <iostream.h>
int n;
void main()
{
double m=3.8;
cout<<"n="<<n<<endl;
fn();
}
void fn()
{
cout<<"m="<<m<<endl;
cout<<"n="<<n<<endl;
}
2. Before you enter the following program in the computer, please read it and write down the output results of the program. Then, you can test the results in the computer by compiling and running it in VC++6.0.
#include <iostream.h>
void func();
int n=1;
int main()
{
static int x=5;
int y;
y=n;
cout<<"x="<<x++<<", y="<<++y<<", n="<<n<<endl;
func();
cout<<"x="<<x++<<", y="<<++y<<", n="<<n<<endl;
func();
}
void func()
{
static int x=4;
int y=10;
x+=3;
n+=10;
y+=n;
cout<<"x="<<x<<", y="<<y<<", n="<<n<<endl;
}
3. Before you enter the following program in the computer, please give the results of the following program of Macros. Then, you can test the results in the computer by compiling and running it in VC++6.0.
#include <iostream.h>
#define f(x) x*x
void main()
{
cout<<f(4+4)<<endl;
cout<<f(2+2)<<endl;
cout<<f(4+4)/f(2+2)<<endl;
}
4. Based on the following namespace and what we have learned about namespace, please use two or three different ways to call the namespace in the main function. The program should be designed by modular programming and tell the role of the namespace.
namespace My {
int Add(int, int) ;
int Mul(int, int) ;
}
int My::Add(int a, int b)
{
return a+b;
}
int My::Mul(int a, int b)
{
return a*b;
}
namespace Your {
int Add(int, int) ;
int Mul(int, int) ;}
int Your::Add(int a, int b)
{
return a-b;
}
int Your::Mul(int a, int b)
{
return a/b;
}
追问:第4个帮帮忙,,,高手。。