exp 1 warm uphome.ustc.edu.cn/~xw2016/exp1.pdf · 2020-02-13 · exp 1 warm up wei xiong 这个pdf...
Post on 02-Aug-2020
1 Views
Preview:
TRANSCRIPT
Conversion Output Specification
%d 有符号十进制整数
%f 十进制浮点数
%c 单个字符
%s 字符串
%ld long int
Exp 1 Warm up
Wei Xiong
这个pdf主要是为了帮助大家简单复习一下C语言, 如果你觉得你C语言已经忘记的差不多了, 这份文档可以帮你重新熟悉一下这门编程语言, 由于这门课的编程实验比较简单, 我不会写太详细或者太复杂的内容, 毕竟这是一门开给数学学院和管理学院的计算机课程。 不需要对自己编程能力有所怀疑, 通过第一个实验, 你的C语言能力会有长足的进步, 只要你自己完成一个完整的, 实现了大部分要求的功能的程序。
如果你对编程比较有兴趣, 我强烈建议你自己阅读 C++ primer plus, C++ primer, C primer plus 等书籍, 同时自学python语言。
1 实验环境
dev cppvisual studio(配置见附录)
2 C语言语法复习
以下代码例子部分来自C primer plus, C++ primer plus 以及部分网上的blog.
2.1 Hello world
2.2 prinf函数与scanf函数
#include <stdio.h>
int main()
{
printf("世界, 吃了吗?\n");//statement
return 0; // explicitly return 0.
}
#include <stdio.h>
int main()
{
int word = 65;
printf("Characters: %c %c \n", 'a', 65);
printf("Decimals: %d %ld\n", 1977, 650000L);
printf("Width trick: %*d \n", 5, 10);
printf("%s \n", "A string");
printf("floats: %4.2f\n", 3.1416); // 4是宽度, 2是保留的位数
2.3 Function and Variable
C语言的变量需要先定义后使用, 同时, 当所有代码都在一个文件里写的时候, 定义函数有两种方法, 一种是把函数的整个定义写在 "main" 函数之前, 一种是在 "main" 函数之前给出函数原型, 再在"main" 函数之后给出函数完整定义。
printf("floats: %4.6f\n", 3.1416);
printf("word as int, char: %d, %c\n", word, word);
return 0;
}
/*
Characters: a A
Decimals: 1977 650000
Width trick: 10
A string
floats: 3.14
floats: 3.141600
word as int, char: 65, A
*/
#include <stdio.h>
int main()
{
int age;
float assets;
char pet[30], text[30];
printf("Enter your age, assets, and favorite pet.\n");
scanf("%d %f", &age, &assets); // 对int, char, float, double 等变量需要&
scanf("%s", pet); // 向一个数组输入字符串不需要 &
printf("%d $%.2f %s\n", age, assets, pet);
printf("Now please enter I love you:\n"); // blog上找到例子, 别吐槽
scanf("%s", text);
printf("%s\n", text); // scanf 遇到空格、回车就停, 所以无法输入带空格的字符串
return 0;
}
/*
Input:
38
92360.88 11ama
I love you
Output:
38 $92360.88 11ama
I
*/
// 一个可以接受带空格的字符串的方法是, 指定scanf遇到换行符停止接收
getchar(); // 接收掉在缓冲区的换行符, 否则就直接停止接收了!
scanf("%[^\n]", text);
// 更多情况请百度关键词 "scanf 空格"
#include <stdio.h>
void func1(int num);
这门课比较常用的数据类型有:
再补充一个结构体的例子:
void func2(int num)
{
printf("My favorite number is %d since I am a big fan of Lion Messi. \n", num);
}
int main()
{
int num1 = 7, num2 = 10; // type_name variable_name;
printf("I will summon the func1 function and func2 function! \n");
func1(num1);
func2(num2);
return 0;
}
void func1(int num)
{
printf("My favorite number is %d since I am a big fan of Cristiano Ronaldo. \n",
num);
}
/*
I will summon the func1 function and func2 function!
My favorite number is 7 since I am a big fan of Cristiano Ronaldo.
My favorite number is 10 since I am a big fan of Lion Messi.
*/
// 首先你可能需要一些常量, 你可以选择以下两种方式之一
#define PI 3.1415926
double const PI = 3.1415926;
int a;
double b; // 当你需要浮点数, 请直接使用double, 直到有一天你开始思考你的程序是否可以使用float
char c;
long int d;
typedef struct LNode {
double coef;
int expn;
LNode *next;
}Lnode, *pNode, *LinkList;
Lnode node; // node类型为LNode结构体
LinkList L; // L 是一个LNode指针
LinkList Polyn[N]; // Polyn[] 是一个长度N的 LNode* 数组
// bool 类型
bool is_ready = true;
// The literals true and false can be converted to int
int ans = true; // ans assigned 1
int promise = false; // promise assigned 0
bool start = -100; // start assigned true
bool stop = 0; // stop assigned false
// 实现极坐标和笛卡尔坐标的相互转换
#include <iostream>
2.4 代码可读性
这里介绍一些约定俗成的代码格式, 尽管它并不影响代码运行, 但是为了方便你的代码管理, 以及以后与他人的合作, 从现在起选择一个你习惯的代码书写格式是有必要的, 因为“程序不是写给自己看的,是写给别人看的”。
一般而言, 除了约定俗成的循环变量我们使用单一字母'i, j. k' 外, 变量命名最好体现其含义, 缩进与空格添加的一些约定可以参考下面的形式。注意:不同的团体和公司有各自的编程规范, 在我们训练的初期, 选择一个统一的编程规范即可, 不必完全相同, 但务必保证代码可读性。
#include <cmath>
struct polar
{
double distance;
double angle;
};
struct rect
{
double x;
double y;
};
polar rect_to_polar(rect xypos);
void show_polar(polar dapos);
polar rect_to_polar(rect xypos)
{
polar answer;
answer.distance =
sqrt( xypos.x * xypos.x + xypos.y * xypos.y);
answer.angle = atan2(xypos.y, xypos.x);
return answer;
}
void show_polar(polar dapos)
{
const double Rad_to_deg = 57.29577951;
// cout是c++里的输出函数
cout << "distance = " << dapos.distance;
cout << ", angle = " << dapos.angle * Rad_to_deg;
cout << " degree\n";
}
# include <stdio.h>
int func(int, int, int);
int main()
{ // 函数花括号单独占一行
int feet, fathoms; // 为变量选择体现含义的名称
int myStudentCount, myFirstName; // Camel-case, 骆驼命名法, 第一个单词小写, 之后每个逻辑
断点大写
// 选择下划线分割也是合理的, 但是请注意习惯的一致性
// 在表达式的运算符两侧都加一个空格
fathomos = 2;
feet = 6 * fathoms;
2.5 指针与引用
首先需要提醒大家的是实参和形参的问题, 当我们调用函数, 传递参数的时候, 程序会复制一份参数给子函数使用, 因此在子函数中修改传递来的参数不会对上一级中的实参影响, 但是我们有时候希望对实参进行修改, 这就需要用到指针, 但是C++的引用语法可以让我们更加方便地实现这一功能。
func(1, 2, 3); // 参数逗号左边不加空格, 右边添加一个空格
printf("There are %d feet in %d fathoms!\n", feet, fathoms);
if (3 == 5) { // if, while 等的花括号是否换行都可以, 但是注意风格的一致性
statement1;
stetement2;
}
if (3 != 5)
{
statement1;
statement2;
}
return 0;
}
#include <stdio.h>
void swap1(int a, int b)
{
int temp = a;
a = b;
b = temp;
}
void swap2(int* a, int* b)
{
int temp = *a;
*a = *b;
*b = temp;
}
void swap3(int &a, int &b)
{ // 引用符号可以使函数直接访问原始参数(实参)
int temp = a;
a = b;
b = temp;
}
int main()
{
int a = 1, b = 2;
int* p, * q;
p = &a;
q = &b;
swap1(a, b);
printf("a = %d, b = %d \n", a, b);
a = 1;
b = 2;
swap2(p, q);
printf("a = %d, b = %d \n", a, b);
2.6 switch, while, for
需要注意switch找到其中一个case, 例如说下面的case 'b', 假设你不执行break, 程序将会从 'b' 开始 执行, 一路往下直到break或者执行所有case. 因此如果你想实现的是一个菜单, break 是有必要加的。
a = 1;
b = 2;
swap3(a, b);
printf("a = %d, b = %d \n", a, b);
while (1);
return 0;
}
/*
a = 1, b = 2
a = 2, b = 1
a = 2, b = 1
/*
/* animals.c -- uses a switch statement */
#include <stdio.h>
#include <ctype.h>
int main()
{
char ch;
printf("Give me a letter of the alphabet, and I will give ");
printf("an animal name\nbeginning with that letter.\n");
printf("Please type in a letter; type # to end my act.\n");
while ((ch = getchar()) != '#')
{
if ('\n' == ch)
continue;
if (islower(ch)) /* lowercase only */
switch (ch)
{
case 'a':
printf("argali, a wild sheep of Asia\n");
break;
case 'b':
printf("babirusa, a wild pig of Malay\n");
break;
case 'c':
printf("coati, racoonlike mammal\n");
break;
case 'd':
printf("desman, aquatic, molelike critter\n");
break;
case 'e':
printf("echidna, the spiny anteater\n");
break;
case 'f':
printf("fisher, brownish marten\n");
break;
default:
printf("That's a stumper!\n");
} /* end of switch */
else
printf("I recognize only lowercase letters.\n");
while (getchar() != '\n')
continue; /* skip rest of input line */
'for' 与 'while' 都是C语言中的循环语句, 当测试条件满足, 程序会反复地被执行:
printf("Please type another letter or a #.\n");
} /* while loop end */
printf("Bye!\n");
while (1);
return 0;
}
/*
Give me a letter of the alphabet, and I will give an animal name
beginning with that letter.
Please type in a letter; type # to end my act.
a [enter]
argali, a wild sheep of Asia
Please type another letter or a #.
dab [enter]
desman, aquatic, molelike critter
Please type another letter or a #.
# [enter]
Bye!
*/
// 一直接收输入, 直到用户输入结束标志时结束
#include <stdio.h>
int main()
{
long num;
long sum = 0L; /* initialize sum to zero */
int status;
printf("Please enter an integer to be summed ");
printf("(q to quit): ");
status = scanf("%ld", &num);
while (status == 1) /* == means "is equal to" */
{
sum = sum + num;
printf("Please enter next integer (q to quit): ");
status = scanf("%ld", &num);
}
printf("Those integers sum to %ld.\n", sum);
return 0;
}
/*
Please enter an integer to be summed (q to quit): 1
Please enter next integer (q to quit): 2
Please enter next integer (q to quit): 3
Please enter next integer (q to quit): 4
Please enter next integer (q to quit): 5
Please enter next integer (q to quit): q
Those integers sum to 15.
*/
// 另一个简单的例子
#include <stdio.h>
int main()
{
int n = 5;
while (n < 7) {
printf("n = %d\n", n);
n++;
printf("Now n = %d\n", n);
最后提供一个do-while的小例子
2.7 递归
}
printf("The loop has finished.\n");
return 0;
}
/*
n = 5
Now n = 6
n = 6
Now n = 7
The loop has finished.
*/
// 需要注意的是, while与for在进入循环的时候就会检查一次测试条件, 而do-while在进入循环的时候不会检查
测试条件
#include <stdio.h>
int main()
{
int n = 7;
for(;n < 7;n++) // 这个循环将不会进入
printf("n = %d\n", n);
printf("The loop has finished.\n");
while (1);
return 0;
}
#include <stdio.h>
int main()
{
int n;
printf("Please enter a number in the range of 1-10 to find: ");
printf("my favorite number\n");
// n没有初始化, 如果你使用while, 进入循环的时候将会测试条件, 报错
do {
scanf("%d", &n);
} while (n != 7);
printf("Yes! My favorite number is 7!\n");
return 0;
}
/*
Please enter a number in the range of 1-10 to find: my favorite number
1
2
4
6
7
Yes! My favorite number is 7!
*/
3 第一次实验: 多项式运算器
实验要求可以在这里看到: http://staff.ustc.edu.cn/~ypb/exp/exp_dsdb.pdf
分析:
实验需要完成一个多项式运算器, 根据多项式的特点,我们可以使用数据结构分别存储其一组系数与指数,由于多项式可以按照指数大小有序排列,适宜用 线性表 存储,并且相当一部分功能需要删减,移动结点,因此 单链表 比顺序表更加合适,所以我们选择单链表来实现这个运算器。
为了代码的简洁,我们选择 带头结点的链表.
在以完成所有实验内容为目标的前提下, 这个程序将会有十几个函数, 并且许多函数会依赖于之前实现的函数(例如, 乘法依赖于加法, 除法依赖于乘法), 因此, 在每完成一个函数的编写后, 进行测试是有必要的, 我们在这里会给大家提供一些测试点, 大家可以对自己的程序进行测试, 比对标准输出.
3.1 数据结构
#include <stdio.h>
void countdown(int n);
int main()
{
countdown(4);
return 0;
}
void countdown(int n)
{
using namespace std;
printf("Counting down... %d (n at %p) \n",n, &n);
if (n > 0) {
countdown(n - 1);
}
printf("%d: Kaboom! (n at %p)\n", n, &n);
}
// 五次调用中,statement1 和 statement2 的执行顺序是正好相反的: Last in First out (LIFO)
// 在学习栈结构后, 你会理解程序是如何管理这个过程的
/*
Counting down... 4 (n at 00EFFA64)
Counting down... 3 (n at 00EFF98C)
Counting down... 2 (n at 00EFF8B4)
Counting down... 1 (n at 00EFF7DC)
Counting down... 0 (n at 00EFF704)
0: Kaboom! (n at 00EFF704)
1: Kaboom! (n at 00EFF7DC)
2: Kaboom! (n at 00EFF8B4)
3: Kaboom! (n at 00EFF98C)
4: Kaboom! (n at 00EFFA64)
*/
#define N 10
typedef int Status;
/*一个简便的方法是创建一个全局的指针数组来管理多项式, */
typedef struct LNode {
double coef;
int expn;
LNode* next;
}LNode, * pNode, * LinkList;
3.2 创建多项式
LinkList Polyn[N];
Status InitList(LinkList &L)
{ // 带头节点
L = (LinkList)malloc(sizeof(LNode));
L->next = NULL;
return true;
}
/* Destroy: L == NULL*/
void destroyPolyn(LinkList& L)
{
if (!L)
return;
pNode p = L, q; // p 拉住指针L指向的结构体
L = NULL; // L作为一个指针的值(也就是它指向的地址)赋值为NULL
while (p) {
q = p;
p = p->next;
free(q);
}
}
void createPolyn(LinkList& L, int m); // 接收m组输入
void createPolyn(LinkList& L); // 由用户自己选择何时接收结束
// 提示, 可以约定当系数和指数都是0的时候结束输入, 然后使用while循环进行判断
// 请注意, 由于用户输入不一定有序, 用户输入可能有同类项, 你的算法应当能够合并同类项与保持有序
pNode makeNode(double coef, int expn)
{
pNode node = new LNode;
node->coef = coef;
node->expn = expn;
node->next = NULL;
return node; // return a pointer here
}
// Hint: for convenience, we implement the insert action as a function
void insertNode(LinkList L, pNode node) // from large to small
{
pNode p = L, q = L->next;
if (abs(node->coef) <= EPSILON) // the coefficient is too small, e.g., <1e-7
return;
while (q && node->expn < q->expn) { // find the right place to insert
p = q;
q = q->next;
}
if (!q) { // new node is inserted at the end
p->next = node;
node->next = NULL;
}
else if (node->expn == q->expn) { // merge
if (abs(node->coef + q->coef) <= EPSILON)
p->next = q->next;
else
q->coef += node->coef;
delete node;
3.3 打印多项式
3.4 求和与求差
3.5 求值, 微分, 积分
}
else {
p->next = node;
node->next = q;
}
}
void printNode(pNode node) {
if (node->expn > 1)
printf("%.4lfx^%d", node->coef, node->expn);
else if (node->expn == 1)
printf("%.4lfx", node->coef);
else
printf("%.4lf", node->coef);
}
void printPolyn(LinkList L) {
if (!L) { printf("NULL\n"); return; }
if (!L->next) { printf()"0.0000\n"); return; }
pNode p;
printNode(L->next);
for (p = L->next->next; p; p = p->next) {
if (p->coef > 0) printf("+");
printNode(p);
}
printf("\n")
}
// 我们需要修改Lc的值, 所以我们加上了引用, 当然要实现这个功能, 二级指针也是一个选择
void addPolyn(LinkList La, LinkList Lb, LinkList& Lc) // La + Lb 储存在Lc
{
pNode pa, pb, pc, tempnode;
if (!Lc)
initPolyn(Lc);
copyPolyn(Lb, Lc); // O(|Lb|)
pa = La->next;
pb = Lb->next;
pc = Lc;
// then, we apply the union algorithm
while (pa && pb) {
// do something;
}
}
void subPolyn(LinkList La, LinkList Lb, LinkList& Lc); // 求和与求差的逻辑完全一致
3.6 乘除法
4 测试点
由于我们并不使用oj进行测试, 程序的接口可能并不一致, 我会在每个测点中描述其逻辑, 你可以新建一个记事本, 把符合自己程序接口的测试点提前打好, 并复制输入。对比了一下当年我给17信同学的测点和今天准备的测点, 我太善良了(严肃)
4.1 测点1
不带说明的测试点:
double valuePolyn(LinkList L, double x) {
pNode p = L->next;
double val = 0;
// for (not end node)
if (abs(p->coef) >= EPSILON) val += p->coef * pow(x, p->expn);
return val;
}
// 定积分可以通过不定积分+求值函数组合直接调用求取
// 由于多项式的特殊性, 不定积分与微分都是逐个结点操作, 与求值一样, 从头结点逐个结点操作即可
void IndefiniteIntegral(LinkList L1, LinkList& L2);
void Differential(LinkList L1, LinkList& L2);
void multiPolyn(LinkList La, LinkList Lb, LinkList& Lc);
// 一个朴素的算法是, 首先实现一个插入结点的函数, 然后进行两层循环
void insertNode(LinkList L, pNode node);
for (pa = La->next; pa; pa = pa->next)
for (pb = Lb->next; pb; pb = pb->next) {
tempnode = ...;
insertNode(Lc, tempnode);
}
// 其中, insertNode 把tempnode插入到Lc中并保持有序.
void divPolyn(LinkList La, LinkList Lb, LinkList& Lc);
// 请百度多项式除法
1
1
1 2
2 1
1 0
0 0
2
1
3
1 2
2
2
4
1 2 3
5
3 2 4
2
3
2
4
8
2
2
0
2
2
0
/* 测试函数:
void initPolyn(LinkList& L);
void destroyPolyn(LinkList& L);
void printPolyn(LinkList L);
void createPolyn(LinkList& L);
void addPolyn(LinkList La, LinkList Lb, LinkList& Lc);
void subPolyn(LinkList La, LinkList Lb, LinkList& Lc);
*/
// 选择功能1(创建多项式), 选择多项式存储的位置(数组下标1), 输入多项式(系数, 指数):
1.0000x^2+2.0000x+1.0000
// 选择功能2(显示多项式), 显示的多项式是多项式1
1
1
1 2
2 1
1 0
0 0
2
1
// 1.0000x^2+2.0000x+1.0000
// 选择功能3(复制多项式), 选择多项式存储的位置(数组下标2)
// 显示多项式
3
1 2
2
2
// 1.0000x^2+2.0000x+1.0000
// 4是加法, 1多项式+2多项式储存在3号下标
4
1 2 3
// 5是减法, 3多项式-2多项式储存在4号下标
5
3 2 4
4.2 测点2
2
3
// 2.0000x^2+4.0000x+2.0000
2
4
// -1.0000x^2-2.0000x-1.0000
8
2
2
0
// NULL
2
2
// 0.0000
0
1
0
1 1
-1 1
2 2
-2 2
3 3
-3 3
4 4
-4 4
5 5
-5 5
6 6
-6 6
7 7
-7 7
100.234 109
0 0
2
0
1
1
1 2
2 1
1 0
0 0
1
2
1 3
2 2
1 1
0 0
4
1 2 3
5
1 2 4
2
3
2
4
0
/*测试函数
void createPolyn(LinkList& L); // 测试你的创建函数是否有合并同类项的功能
void addPolyn(LinkList La, LinkList Lb, LinkList& Lc);
void subPolyn(LinkList La, LinkList Lb, LinkList& Lc);
*/
// 选择功能1(创建多项式), 选择多项式存储的位置(数组下标1), 输入多项式(系数, 指数): 100.2340x^109
// 选择功能2(显示多项式), 显示的多项式是多项式0
0
1 1
-1 1
2 2
-2 2
3 3
-3 3
4 4
-4 4
5 5
-5 5
6 6
-6 6
7 7
-7 7
100.234 109
0 0
2
0
// 100.2340x^109
// 再创建两个多项式
1
1
1 2
2 1
1 0
0 0
1
2
1 3
2 2
1 1
0 0
// 加法: 1 + 2 存在3
4
1 2 3
// 减法: 2 - 1 存在4
4.3 测点3
5
1 2 4
2
3
// 1.0000x^3+3.0000x^2+3.0000x+1.0000
2
4
// 1.0000x^3+1.0000x^2-1.0000x-1.0000
0
1
1
1 2
2 1
1 0
0 0
2
1
3
1 2
4
1 2 3
5
3 2 4
6
1 0.5
7
1
8
2
9
2 1
1 3
9
3 2
0
9
3 3
2 1
10
4 5
11
5 6
12
6 -1 1
2
0
2
1
2
2
2
3
2
4
2
5
2
6
2
7
2
8
2
9
0
/*测试函数
void IndefiniteIntegral(LinkList L1, LinkList& L2);
double valuePolyn(LinkList L, double x);
void Differential(LinkList L1, LinkList& L2);
void Integral(LinkList L1, LinkList& L2);
*/
1
1
1 2
2 1
1 0
0 0
2
1
// 1.0000x^2+2.0000x+1.0000
3
1 2
4
1 2 3
5
3 2 4
6
1 0.5
2.2500
8
2
9
2 1
1 3
9
3 2
0
9
3 3
2 1
10
4 5
11
5 6
12
6 -1 1
-0.6667
2
0
// NULL
2
2
// 1.0000x^3
2
3
// 2.0000x^2+2.0000x
2
4
// -1.0000x^2-2.0000x-1.0000
2
5
// -2.0000x-2.0000
2
6
// -1.0000x^2-2.0000x
2
7
// NULL
2
8
4.4 测点4
// NULL
2
9
// NULL
0
1
0
1 1
1 0
0 0
1
1
1 1
-1 0
0 0
13
0 1 2
13
0 2 3
13
0 2 4
13
0 4 5
13
0 5 6
13
1 5 7
13
6 7 8
13
6 8 9
2
0
2
1
2
2
2
3
2
4
2
5
2
6
2
7
2
8
2
9
0
/*测试函数
void multiPolyn(LinkList La, LinkList Lb, LinkList& Lc);
*/
// 创建两个多项式
1
0
1 1
1 0
0 0
1
1
1 1
-1 0
0 0
// 0 x 1 存在2
13
0 1 2
// 0 x 2 存在3
13
0 2 3
13
0 2 4
13
0 4 5
13
0 5 6
13
1 5 7
13
6 7 8
13
6 8 9
4.5 测点5
2
0
// 1.0000x+1.0000
2
1
// 1.0000x-1.0000
2
2
// 1.0000x^2-1.0000
2
3
// 1.0000x^3+1.0000x^2-1.0000x-1.0000
2
4
// 1.0000x^3+1.0000x^2-1.0000x-1.0000
2
5
// 1.0000x^4+2.0000x^3-2.0000x-1.0000
2
6
// 1.0000x^5+3.0000x^4+2.0000x^3-2.0000x^2-3.0000x-1.0000
2
7
// 1.0000x^5+1.0000x^4-2.0000x^3-2.0000x^2+1.0000x+1.0000
2
8
// 1.0000x^10+4.0000x^9+3.0000x^8-8.0000x^7-14.0000x^6+14.0000x^4+8.0000x^3-3.0000x^2-
4.0000x-1.0000
2
9
// 1.0000x^15+7.0000x^14+17.0000x^13+7.0000x^12-43.0000x^11-77.0000x^10-
11.0000x^9+99.0000x^8+99.0000x^7-11.0000x^6-77.0000x^5-
43.0000x^4+7.0000x^3+17.0000x^2+7.0000x+1.0000
0
1
0
1 2
2 1
1 0
0 0
1
1
1 1
1 0
0 0
1
2
10 10
8 9
2 3
0 0
14
1 0 3
14
2 1 4
14
2 0 5
2
0
2
1
2
2
2
3
2
4
2
5
0
1
0
1 2
2 1
1 0
0 0
1
1
1 1
1 0
0 0
1
2
10 10
8 9
2 3
0 0
14
1 0 3
14
2 1 4
14
2 0 5
2
0
// 1.0000x^2+2.0000x+1.0000
4.6 测点6
2
1
// 1.0000x+1.0000
2
2
// 10.0000x^10+8.0000x^9+2.0000x^3
2
3
// 0.0000
2
4
// 10.0000x^9+2.0000x^8+2.0000x^7-2.0000x^6-2.0000x^2
2
5
// 10.0000x^8
0
1
0
1 2
2 1
1 0
0 0
1
1
1 1
1 0
0 0
1
2
10 10
8 9
2 3
0 0
15
1 0 3
15
2 1 4
15
2 0 5
2
0
2
1
2
2
2
3
2
4
2
5
0
1
0
1 2
2 1
1 0
0 0
1
1
1 1
1 0
0 0
1
2
10 10
8 9
2 3
0 0
// 选择功能15(求余), 1对0求余存在3
15
1 0 3
15
2 1 4
15
2 0 5
2
0
// 1.0000x^2+2.0000x+1.0000
2
1
// 1.0000x+1.0000
2
2
// 10.0000x^10+8.0000x^9+2.0000x^3
2
3
// NULL
4.7 测点7
2
4
// NULL
2
5
// NULL
0
1
0
1 3
3 2
3 1
1 0
0 0
1
1
1 4
4 3
6 2
4 1
1 0
0 0
1
2
1 2
3 1
1 0
0 0
19
3
(0+1*2+2*2)/(1+2)
19
4
(0*3+2/3)*(1+3)
2
3
2
4
0
/*测试函数
void siZeYunSuan(char exp[], LinkList& L);
*/
1
0
5 环境配置
5.1 vs下载
通过百度搜索visual studio, 进入官网,点击下载
1 3
3 2
3 1
1 0
0 0
1
1
1 4
4 3
6 2
4 1
1 0
0 0
1
2
1 2
3 1
1 0
0 0
19
3
(0+1*2+2*2)/(1+2)
19
4
(0*3+2/3)*(1+3)
2
3
// 1.0000x^2
2
4
//
1.0000x^9+7.0000x^8+22.0000x^7+34.0000x^6+26.0000x^5+11.0000x^4+7.0000x^3+8.0000x^2+1.0
000
0
打开下载程序, 进入模块选择, 如果你只打算写C/C++, 可以只安装如下所勾选的那个模块。
安装完毕后, 打开vs
5.2 hello world
点击文件, 新建项目, 空项目
新建项目后, 在右侧的源文件右键, 添加, 选择C++文件
为了执行代码, 我们点击调试中的开始执行
5.3 使用C中的函数
你们很快会发现, vs中的scanf是使用不了的, 这是因为scanf函数有一定的危险性, 在vs中有一定的修改, 为了使得传统的scanf能够使用, 我们如下图打开属性
选择C/C++, 与处理器, 在如图所示的预处理器定义的末尾添加: ;_CRT_SECURE_NO_WARNINGS
top related