第一、基本程序结构都一样
第二、输出与输入不同
C++的输出是:cout << "!!!Hello World!!!" << endl;
C#的输出是:console.write("!!!Hello World!!!");//输出语句,不自动换行
C++的输入是:
int score = 0;
cout << "用户输入分数:" << endl;
cin >> score;
C#的输入是:
int score = 0;
console.write("用户输入分数:");
score = console.ReadKey();//输入语句,不自动换行
第三,函数的调用不同
C++的函数调用,需要在调用之前,做个声明
如:int BaseTest1();
C#的函数调用,不需要在调用之前做声明,直接调用即可。
第四、格式习惯不同
C++的格式习惯如下
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
C#的格式习惯如下,主要不同在大括号
int main()
{
console.write("!!!Hello World!!!");
return 0;
}
#include <iostream>
using namespace std;
/*
下面是2个函数调用声明
*/
int BaseTest1();
int BaseTest2();
/*
程序入口函数
*/
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
BaseTest1();
BaseTest2();
return 0;
}
/*
下面是16个函数
*/
/*
选择结构 单行if语句
*/
int BaseTest1() {
//用户输入分数,如果分数大于60,视为考上一本大学,在屏幕上输出
//1.用户输入分数
int score = 0;
cout << "input your score:" << endl;
cin >> score;
//2.打印用户输入的分数
cout << "your score is " << score << endl;
//3.判断分数是否大于600,如果大于600,那么输出
if (score > 600)
{
cout << "Congratulations on entering a key university" << endl;
}
system("pause");
return 0;
}
/*
选择结构 多行if语句
*/
int BaseTest2() {
//输入考试分数,如果大于600,视为考上一本,在屏幕输出
//如果没考上一本大学,打印未考上一本大学
//1.输入考试分数
int score = 0;
cout << "input your score:" << endl;
cin >> score;
//2.打印用户输入的分数
cout << "your score is " << score << endl;
//3.判断
if (score > 600)
{
cout << "Congratulations on entering a