通过实践

  了解和实践了VS2019平台上的基本操作:

  打开VS2019、新建文件、打开文件、调试运行自动生成的代码、添加用户代码后调试运行等、……。新建、编写、调试、运行与测试。

  制作一个带有标准IO(键盘输入与显示器输出)的C++程序语言与结构及其代码,……。这是一个框架-格式、模板、基础、扩充出发点。

  在标准IO模板中添加一些基本的数学运算-四则混合运算、重复的连加连减连乘连除等。

  由于是算术问题的计算机处理描述,问题的提法、算法分析、程序结构等问题比在此解说。通过阅读程序的基本功,相信初学者也可以读懂理解。当然,各个初始值的的设置,循环次数的设置等还是可以有多种变化的。读者可以自己去修改、理解程序描述的多样性。也可以找到用于一般性标准计算程序的设置与用户输入参数控制等。

  下面先看一下从原来的程序扩充而来的代码:

  自动生成的部分:

  #include <iostream>

  int main()

  {

  std::cout << "Hello World!

  ";

  }

  添加了标准IO的部分

  #include <iostream>

  int main()

  {

  //变量声明-获取内存空间—因为要为输入数据提供放置的地方

  int Intdata1,add,multiply;

  float RFdata1,subtract,divide;

  //数据信息标准IO

  std::cout << "Enter an integer :

  ";

  std::cin >> Intdata1;

  std::cout << "Hello World! data processing beginning:

  ";

  //数据信息处理结果的标准输出

  std::cout << " Keyboard input integer: "<< Intdata1 << "

  ";

  std::cout << "The program is over!

  ";

  }

  扩充、添加了在标准IO模板中的数据处理部分

  // VS2019Four_Mixed_Operations_C++IO.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。

  //

  #include <iostream>

  int main()

  {

  //变量声明-获取内存空间

  int Intdata1, add, multiply, addS, multiplyS, finaleN;

  float RFdata1, subtract, divide,subtractS, divideS, mixed;

  //数据信息标准IO

  std::cout << "Enter an integer :

  ";

  std::cin >> Intdata1;

  std::cout << "Enter an real :

  ";

  std::cin >> RFdata1;

  std::cout << "Hello World! data processing beginning:

  ";

  //数据处理的描述-过程与行为

  //Four mixed operations

  add = Intdata1 + Intdata1;

  multiply = 3 * Intdata1;

  subtract = RFdata1 - Intdata1;

  divide = RFdata1 / Intdata1;

  mixed = add/ RFdata1 + Intdata1- subtract * multiply;

  //Continuous addition, subtraction, multiplication, and division

  std::cout << "Enter an integer: the mantissa of continuous addition

  ";

  std::cin >> finaleN;

  addS = 0;

  for (size_t i = 0; i <= finaleN; i++)

  {

  addS = addS +i;

  }

  std::cout << "Enter an integer: the mantissa of continuous subtraction

  ";

  std::cin >> finaleN;

  subtractS = 100;

  for (size_t i = 0; i <= finaleN; i++)

  {

  subtractS = subtractS-i;

  }

  std::cout << "Enter an integer: the mantissa of continuous multiplication

  ";

  std::cin >> finaleN;

  multiplyS= 1;

  for (size_t i = 1; i <= finaleN; i++)

  {

  multiplyS = multiplyS * i;

  }

  std::cout << "Enter an integer: the mantissa of continuous division

  ";

  std::cin >> finaleN;

  divideS = 100;

  for (size_t i = 1; i <= finaleN; i++)

  {

  divideS = divideS / i;

  }

  //数据信息处理结果的标准输出

  std::cout << "

  ";

  std::cout << "Adding two integers: " << add << "

  ";

  std::cout << "3 multiply integers: " << multiply << "

  ";

  std::cout << "Subtracting real numbers and integers: " << subtract << "

  ";

  std::cout << "RFdata1 / Intdata1= " << divide << "

  ";

  std::cout << " add/ RFdata1 + Intdata1- subtract * multiply= " << mixed << "

  ";

  std::cout << "

  ";

  std::cout << "The result of continuous addition: " << addS << "

  ";

  std::cout << "The result of continuous subtraction: " << subtractS << "

  ";

  std::cout << "The result of continuous multiplication: " << multiplyS << "

  ";

  std::cout << "The result of continuous division: " << divideS << "

  ";

  std::cout << "

  ";

  std::cout << "The program is over!

  ";

  }

  // 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单

  // 调试程序: F5 或调试 >“开始调试”菜单

  运行结果:

  Enter an integer :

  3

  Enter an real :

  4.4

  Hello World! data processing beginning:

  Enter an integer: the mantissa of continuous addition

  5

  Enter an integer: the mantissa of continuous subtraction

  5

  Enter an integer: the mantissa of continuous multiplication

  5

  Enter an integer: the mantissa of continuous division

  5

  Adding two integers: 6

  3 multiply integers: 9

  Subtracting real numbers and integers: 1.4

  RFdata1 / Intdata1= 1.46667

  add/ RFdata1 + Intdata1- subtract * multiply= -8.23636

  The result of continuous addition: 15

  The result of continuous subtraction: 85

  The result of continuous multiplication: 120

  The result of continuous division: 0.833333

  The program is over!

  程序与运行结果举报/反馈