C++全英试题(华南理工大学)

WARNING: MISBEHAVIOR AT EXAM TIME WILL LEAD TO SERIOUS CONSEQUENCE.

SCUT Final Exam

High-Level Language ProgrammingC++)(I)》 Exam Paper B

Notice:     1. Make sure that you have filled the form on the left side of seal line.

2. Write your answers on the answer sheet.

3. This is a close-book exam.

4. The exam with full score of 100 points lasts 120 minutes.

Question No.

I

II

III

IV

V

Sum

Score

Question 1 Choose the correct answer. (40 points, 2 points for each)

1) About arrays, which statement is incorrect? (  D  )

A)  The first element has subscript 0

B)  The name of an array is a constant pointer

数组名称是常量指针,因此++是错误的

C)  Each element of an array is of the same data type

D)  An array can only be initialized but cannot be assigned.

显然可以赋值

问题1 选择正确答案。 (40分,每题2分)

1)关于数组,哪个说法是不正确的?(D)

A)第一个元素的下标为0

B)数组的名称是一个常量指针

C)数组的每个元素都是相同的数据类型

D)数组只能被初始化,不能被赋值。

翻译和解答:

  1. (D)数组只能被初始化但不能被赋值。这个说法是不正确的。在大多数编程语言中,数组可以被初始化并且之后的操作中可以被赋新值。数组是一种数据结构,允许存储和访问多个相同类型的元素,而不仅限于初始化时的数值。

2) which statement is incorrect when we declare: int a[3]? (  B  )

A) the array a has 3 elements

B) the last element of the array a is a[3]

C) the last element of the array a is a[2]

D) The first element of the array a can be obtained using *a

*a读取也是正确的

显而易见的罢

0,1,2

最后是a[2]

3)    In the following statements, which one is correct to initialize a two-dimensional array? (  B )

A)   int aa[3][]={{3,5,6},{5,4,4},{4,5,6}};

B)   int aa[][3]={{1,0},{},{1,1}};

C)   int aa[2][3]={{5,6,3},{8,0},{69}};

D)   int aa[][2]={{6,9},{4,8}};

3) 在以下语句中,哪一个是正确初始化二维数组的方式?(B D)

A) int aa[3][]={{3,5,6},{5,4,4},{4,5,6}};

列必须说

B) int aa[][3]={{1,0},{},{1,1}};

C) int aa[2][3]={{5,6,3},{8,0},{69}};

两行?这个是三行的初始化了

D) int aa[][2]={{6,9},{4,8}};

解释:

在二维数组的初始化中,对于未指定行数的情况,编译器会根据提供的初始值来确定行数。选项D中提供了正确的初始化语法,包括了两行两列的二维数组。

让我们逐个分析为什么其他三个选项是错误的:

A) `int aa[3][]={{3,5,6},{5,4,4},{4,5,6}};`

- 这个选项是错误的,因为在C语言中,只有第一维的大小可以省略,而第二维的大小必须指定。因此,`int aa[3][]` 是不允许的。

B) `int aa[][3]={{1,0},{},{1,1}};`

C) `int aa[2][3]={{5,6,3},{8,0},{69}};`

- 这个选项是错误的,因为第二行 `{8,0}` 不包含足够的元素来填满3列的要求。在二维数组中,每一行的元素数量必须相同。

综上所述,只有选项 B,D (`int aa[][2]={{6,9},{4,8}};`) 提供了正确的二维数组初始化方式。

4) Assume int c=6; which one produces 5 in the following statements? (  B   )

A) c--;

B) --c;

C) ++c;

D) c++;

注释:A选项加括号情况下也产生结果5,有些优先级比较低的时候会产生问题,本次考试选A或B都对。

显而易见

5) If we do not allow to modify a pointer p itself and do not allow to modify the data which p points to, which kind of declaration can be used? (  C )

A) const int *p = 10;

B) int const *p = 10;

C) const int *const p = 10;

D) int * const p = 10;

5) 如果我们不允许修改指针 p 本身,也不允许修改 p 所指向的数据,哪种声明可以使用?(C)

A) const int *p = 10;

B) int const *p = 10;

C) const int *const p = 10;

D) int * const p = 10;

答案:

C) const int *const p = 10;

解释:

- `const int *p`: 这种声明表示指针 p 指向的数据是常量,不能通过指针 p 修改数据,但可以修改指针 p 本身。

- `int const *p`: 与上面相同,表示指针 p 指向的数据是常量。

- `const int *const p`: 这个声明表示指针 p 本身是常量,不能通过指针 p 修改其指向的数据,也不能修改指针 p 本身。

- `int * const p`: 这个声明表示指针 p 本身是常量,不能通过指针 p 修改其指向的地址,但可以通过指针 p 修改指向的数据。

因此,只有选项 C (`const int *const p = 10;`) 满足不允许修改指针和指针所指向的数据的要求。

6)    If we have : int x=14, y=5;  int a=7, b=3;  the value of expression (x+y)/2+a%b  would be (  D   )。

A)  9.5               B)  10.5                    C)   9                D)   10

显而易见

7) Assume int x=20, y=34; in the following statements, which one is evaluated to true?  (   C  )

A) !(x<y);

B) x>y;

C) y<x || x>0

D) !(x<0 || x<y)

显而易见

8) About the default arguments(默认参数) which one is correct?  (  A   )

A) Default arguments are optional.

B) A function can have only one default argument.

可以有多个

C) A default argument can be put in any place of a function’s parameter list.

不能随便放

D) Default arguments can be specified in the function prototype or definition.

默认参数可以在函数的原型或定义中指定。()

默认参数的指定放在函数原型或者声明中,而不是定义。

本题考查默认参数

函数的默认参数值,即在定义参数的时候同时给它一个初始值。在调用函数的时候,我们可以省略含有默认值的参数。也就是说,如果用户指定了参数值,则使用用户指定的值,否则使用默认参数的值。

默认参数只能在函数声明和原型中指定,而不能在函数定义中是因为函数定义提供了函数的具体实现,而默认参数的值在编译时需要被确定。让我们详细解释这一点:

1. *编译器处理顺序:**

   - 在编译C或C++程序时,编译器按照源文件的顺序逐行处理。

   - 当编译器在源文件中看到函数调用时,它需要知道如何调用该函数,包括参数的个数和类型。这就是为什么函数原型或声明在调用函数之前必须存在的原因。

2. **默认参数的确定:**

   - 默认参数的值是在编译时确定的,而不是在运行时。

   - 函数定义通常包含函数体和实际的代码逻辑,而默认参数的值是用于函数调用的信息。

   - 如果默认参数的值在函数定义中指定,而函数调用在定义之前,编译器无法在调用点确定默认参数的值。

因此,将默认参数的值放在函数原型或声明中,可以使编译器在编译过程中了解函数调用的正确方式,而不需要等到函数的实际实现。这样,即使函数的定义在调用点之后,编译器仍然可以正确生成调用代码。

(9) To initialize an array of characters, which one is NOT correct?  (  D   )

      A) char ss[3]={ 'a','b','c'};           B) char *ss="abc";

         C) char ss[]={'a','b','c'};              D) char ss[3]="abc";

D超过范围了,报错会是4去初始化3

(9) 对于初始化字符数组,哪一个是不正确的?(D)

A) `char ss[3] = {'a', 'b', 'c'};`

B) `char *ss = "abc";`

C) `char ss[] = {'a', 'b', 'c'};`

D) `char ss[3] = "abc";`

答案:

D) `char ss[3] = "abc";`

解释:

- A) 正确。使用花括号的方式初始化字符数组。

- B) 正确。使用字符指针指向字符串字面值。

- C) 正确。使用空的方括号,让编译器根据提供的初始值确定数组的大小。

- D) 不正确。虽然编译器会为字符数组分配足够的空间,但字符串字面值实际上包括一个额外的空字符 '\0',因此在这种情况下,数组大小应该是4而不是3。

所以,选项 D (`char ss[3] = "abc";`) 不是正确的初始化字符数组的方式。

10)  In the following statements, which one is correct?  (  C   )

A) int x=3, y=5; int *const ptr = &x; ptr=&y;

B) int x=3, y=5; const int *const ptr = &x; ptr=&y;

C) int x=3, y =5; int *const ptr = &x; *ptr= y;

不允许修改指向,而是修改了值,合理

D) int x=3, y=5; const int *const ptr = &x; *ptr= 9;

显而易见

11)  In the following statements, which one is incorrect?  (  C   )

A) All pointers can be assigned to a pointer of type void* without casting.

B) some pointers can be subtracted from another pointer.

C) A void * pointer can be directly assigned to a pointer of another type.

D) Assume a pointer is defined to point to an array name. Then this pointer can be used to access the elements of the array.

(11) 在下面的语句中,哪一个是不正确的?(C)

A) 所有指针都可以在没有强制转换的情况下分配给一个类型为 void* 的指针。

B) 一些指针可以从另一个指针中减去。

C) 一个 void* 指针可以直接分配给另一种类型的指针。(不能)

D) 假设一个指针被定义为指向数组名,则这个指针可以用来访问数组的元素。

答案:

C) 一个 void* 指针可以直接分配给另一种类型的指针。

解释:

- A) 正确。`void*` 指针是一种通用指针,可以存储任何类型的地址。

- B) 正确。指针之间的减法运算表示它们之间的偏移量,用于计算元素之间的距离。

- C) 不正确。在C语言中,`void*` 指针需要显式的类型转换,才能分配给其他类型的指针。

- D) 正确。一个指针可以用来访问数组的元素,指向数组的首元素。

因此,选项 C (`一个 void* 指针可以直接分配给另一种类型的指针。`) 是不正确的。

12)  If we declare:  double Test ( double );       typedef double FT ( double ) ;

 FT* pf=Test;,in the following function calls, which one is NOT correct  (   D )?

A)Test (10.1)               B)( * pf )( 10.1)

C) ( pf )( 10.1)                          D)( & pf )( 10.1)

我认为答案有误,答案是B,我认为应该是D

在 C/C++ 中,函数指针的调用有两种方式:`(*pf)(10.1)` 和 `pf(10.1)`,两者是等价的。

所以,选项 B (`(*pf)(10.1)`) 是正确的,而选项 C (`(pf)(10.1)`) 也是正确的。

选项 D (`(&pf)(10.1)`) 是不正确的,因为 `&pf` 取的是指针 pf 的地址,而不是调用函数。

综上所述,正确的答案是 D。

13) if we declare: int a = 9, and int *aPtr = &a, which statement in the following directly gets the value of a? (  B )

A) *&aPtr      B) *aPtr

C) &*aPtr   D) aPtr

显而易见

14) If we have: int b[]={1,2,3 }and int *bPtr = b, which one the following is incorrect? (  D )

A) &b[ 1 ]      B) bPtr +1

C) bPtr++       D) b++

数组名常量指针,不能加加

(14) 如果我们有:`int b[] = {1, 2, 3};` 和 `int *bPtr = b;`,在以下哪个选项是不正确的?(D)

A) `&b[1]`

B) `bPtr + 1`

C) `bPtr++`

D) `b++`

答案:

D) `b++`

解释:

- A) `&b[1]`:取数组 b 中索引为 1 的元素的地址,是正确的。

- B) `bPtr + 1`:指针 bPtr 指向数组 b 的首元素,`bPtr + 1` 表示指针移动到下一个元素的地址,是正确的。

- C) `bPtr++`:后置递增运算符使指针 bPtr 移动到下一个元素的地址,是正确的。

- D) `b++`:这是不正确的。在数组名上使用递增运算符是不允许的,因为数组名是常量指针,无法被修改。

所以,选项 D (`b++`) 是不正确的。

15) About a static variable, which statement is incorrect? (  B  )

A) It is known only in the function in which they are declared

B) A static variable must be initialized when it is declared.

C) If numeric variables of the static storage class are not explicitly initialized by the programmer, they are initialized to zero

D) Next time the function is called, the static local variables retain the values they had when the function last completed.

(15) 关于静态变量,哪个说法是不正确的?(B)

A) 它只在声明它们的函数中可见。

B) 静态变量在声明时必须被初始化。

C) 如果静态存储类的数值型变量没有被程序员显式初始化,它们会被初始化为零。

D) 下一次调用函数时,静态局部变量将保留上次函数完成时的值。

答案:

B) 静态变量在声明时必须被初始化。

解释:

- A) 正确。静态变量的作用域限制在声明它们的函数内。

- B) 不正确。静态变量可以不在声明时初始化,如果没有显式初始化,它们会被默认初始化。对于数值型的静态变量,默认初始化为零。

- C) 正确。如果程序员没有为静态存储类的数值型变量显式提供初始值,它们会被初始化为零。

- D) 正确。静态局部变量在函数调用之间保留它们的值,不像自动变量,它们在每次函数调用时都会被重新初始化。

#include<iostream>
using namespace std;
int main()
{
	static int a;
	cout << a;
}

输出:0

#include<iostream>
using namespace std;
int main()
{ 
	int a;
	cout << a;
}

报错,因为没有初始化

此为区别

因此,选项 B (`静态变量在声明时必须被初始化。`) 是不正确的。

16) About overloaded functions, which statement is incorrect? ( C )

A) Overloaded functions have the same name

B) Overloaded functions have different sets of parameters

C) Overloaded functions can allow the same signature.

D) Compiler selects proper overloaded function to execute based on number, types and order of arguments in the function call(16) 关于重载函数,哪个说法是不正确的?(C)

A) 重载函数具有相同的名称

B) 重载函数具有不同的参数集

C) 重载函数可以允许相同的签名

D) 编译器根据函数调用中参数的数量、类型和顺序选择适当的重载函数执行

答案:

C) 重载函数可以允许相同的签名

解释:

- A) 正确。重载函数具有相同的名称。

- B) 正确。重载函数具有不同的参数集。

- C) 不正确。重载函数必须具有不同的参数列表,不能仅仅通过返回类型或函数名称的不同来重载。

- D) 正确。编译器根据函数调用中的参数信息选择适当的重载函数执行。

因此,选项 C (`重载函数可以允许相同的签名。`) 是不正确的。

17) Which one is the illegal definition of a string “blue”? ( C  )

A) char color[] = “blue”    B) const char *colrPtr = “blue”

C) char color[] = {‘b’, ‘l’, ‘u’, ‘e’}    D) char color[] = {‘b’, ‘l’, ‘u’, ‘e’, ‘\0’}

(17) 下列哪一个是字符串 "blue" 的非法定义?(C)

A) `char color[] = "blue"`

B) `const char *colrPtr = "blue"`

C) `char color[] = {'b', 'l', 'u', 'e'}`

D) `char color[] = {'b', 'l', 'u', 'e', '\0'}`

答案:

C) `char color[] = {'b', 'l', 'u', 'e'}`

解释:

- A) 正确。使用双引号括起来的字符串字面值可以直接赋值给字符数组。

- B) 正确。使用指针指向字符串字面值,`const` 表示字符串内容不可修改。

- C) 不正确。虽然使用花括号初始化字符数组是合法的,但没有以 null 结尾的字符 '\0',这违反了 C 语言中字符串的定义。

- D) 正确。使用花括号初始化字符数组,并在最后添加 null 结尾字符 '\0',形成一个合法的 C 字符串。

简单的说4个都是对的

只是C不符合\0这一规则罢了

因此,选项 C (`char color[] = {'b', 'l', 'u', 'e'}`) 是非法的字符串定义。

18) In the following, which stream manipulator is not sticky? (  C  )

A) setfill     B) setprecision

C) setw    D) setbase

(18) 在以下选项中,哪一个流操作符不是黏性的?(C)

A) `setfill`

B) `setprecision`

C) `setw`

D) `setbase`

答案:

C) `setw`

解释:

- A) `setfill` 设置填充字符,它是黏性的,影响后续的输出。

- B) `setprecision` 设置浮点数的精度,它是黏性的,影响后续的浮点数输出。

- C) `setw` 设置字段宽度,它不是黏性的,只应用于紧接着的一次输出,而不影响后续输出。

- D) `setbase` 设置输出整数的进制,它是黏性的,会影响后续整数的输出。

因此,选项 C (`setw`) 是不黏性的流操纵符。

Setw不是黏性

19) which of the following variable is legal? (  A  )

A) _Yellow     B) yellow-2

C) class                    D) delete

显然

20) const *p means we cannot modify  (  B )

A) the pointer p itself

B) the variable that p points to

C) the data type of p

D) all the options above

(20) `const *p` 表示我们不能修改哪个部分?(B)

A) 指针 p 本身

B) 指针 p 所指向的变量

C) 指针 p 的数据类型

D) 上述所有选项

答案:

B) 指针 p 所指向的变量

解释:

- A) `const *p` 中的 `*p` 表示指向的变量是常量,但指针 p 本身可以被修改。

- B) 正确。`const *p` 表示指向的变量是常量,不允许通过指针 p 修改该变量的值。

- C) `const *p` 中的 `const` 表示指针 p 的数据类型是常量,即指针的类型不能被修改。

- D) 不正确。虽然 `const *p` 中的 `const` 影响了指针 p 所指向的变量,但并没有限制修改指针 p 本身或其数据类型。

因此,选项 B (`指针 p 所指向的变量`) 是正确的。

Question 2: Write the output of the following program. (20 points, 4 points for each

1.

#include <iostream>

using namespace std;

int main()

{ int a=10, b=20;

int *p = &a, *q = &b;    

*p = *p * *q;

  int & ra = a;

ra=a;

int * & rt = q;

*rt = 30;

cout<<"a="<<a<<"\nb="<<b<<"\n*p="<<*p<<"\n*q="<<*q <<"\nra="<<ra<<"\n*rt="<<*rt<<endl;

return 0;

}

ans:

        a=200

        b=30

        *p=200

        *q=30

        ra=200

        *rt=30

显然

2.

#include<iostream>

using namespace std;

int main()

{ int i, s = 0;

  for( i=0; i<5; i++ )

    switch( i )

     { case 0:  s += i;  break;

       case 1:  s += i;  break;

       case 2:  s += i;  break;

       default: s += 2;

     }

  cout<<"s="<<s<<endl;

return 0;

}

ans:

s=7

显然

3

#include<iostream>

using namespace std;

int f2( int, int );

int f1( int a , int b )

{ int c ;

  a += a ; b += b ;

  c = f2( a+b , b+1 );

  return c;

}

int f2( int a , int b )

{  int c ;

  c = b % 2 ;

  return a + c;

}

int main()

{   int a = 3 , b = 4;

    cout << f1( a , b ) << endl;

        return 0;

}

ans:

15

也是没什么坑的

4.

#include <iostream>

using namespace std;

int f(int [],int);

int main()

{ int a[] = { -1, 3, 5, -7, 9, -11 } ;

  cout << f( a, 6 ) << endl ;

}

int f( int a[], int size )

{ int i, t=1 ;

  for( i=0 ; i<size; i ++ )

     if( a[i]>0 )  t *= a[i] ;

  return t;

}

ans:

135

显然

5

#include <iostream>

using namespace std;

struct Node

 { char * s ;

   Node * q ;

 } ;

int main()

{ Node a[ ] = { { "Mary", a+1 }, { "Jack", a+2 }, { "Jim", a } } ;

  Node *p = a ;

  cout << p->s << endl ;

  cout << p->q->s << endl ;

  cout << p->q->q->s << endl ;

  cout << p->q->q->q->s << endl ;

}

ans:

Mary

Jack

Jim

Mary

显然

Question 3: Answer Briefly( 15 points for total)

1. (10 points,  2 for each) What is the meaning of a in each statement?

(1) int * a;               (2) int * a();             (3) int (*a) ();

(4) int *a[2]             (5) int (*a[2])()       

ans:

(1).   整型指针                                            

(2).  返回整型指针的函数                                 

(3).  指向一个返回整型、不带参数的函数的指针             

(4).  包含2个整型指针为元素的数组                         

(5).  包含2个函数指针为元素的数组,指针指向返回整型、不带参数的函数

2. (2 points) In the function prototype int fun(int, int=0);  what does the “int=0” mean?

ans:表示默认参数为0

3. (3 points) What is recursion function? Generally how many parts a recursion function is divided as? what are those part’s functionalities(characteristics)?

ans:recursion function是指递归函数,一般将其为两部分,一部分明确知道其结果,一部分是一个更小规模的原问题

基本问题

一般问题

Question 4: Fill in the blanks2 points for blank 1--7, 3 points for blank 8--9, 20 points for total)  

1. The following function is to sort an array by using selection method.

       一个裸的选择排序

        void selectionSort( int x[],  int n)

{

        int  max, t;

        for (  __【1】_;__【2】_;  i++)

        {

                 t = i;

                 for (int j = i + 1; j < n; j++)         //Finding the largest element  

                         if ( x [ j ] > x [ t ] )  t = j ;

                         if (__【3】_)

                         {

                                  max = x[i];                  //swap elements

                                  x[i] = x[t];

                                  x[t] = max;

                         }

        }

        return;

}

选择排序

void selectionSort(int x[], int n)

{

    int max, t;

    for (int i = 0; i < n - 1; i++) // Blank 1跑n-2次

    {

        t = i;

        for (int j = i + 1; j < n; j++) // Finding the largest element

            if (x[j] > x[t])

                t = j;

        if (t != i) // Blank 3

        {

            max = x[i]; // swap elements

            x[i] = x[t];

            x[t] = max;

        }

    }

    return;

}

2. The following function copies all characters in a string starts at subscript m to another string.

#include<iostream>

using namespace std;

void strcopy(char *str1,char *str2,int m)

{

   char *p1,*p2;

   _____【4】___________; 

   p2=str2;

   while(*p1){

      _____【5】___________;

      _____【6】__________;

   }

}

int main()

{

     int m;

     char str1[80], str2[80];

     gets_s(str1);

      cin>>m;

    ______【7】______;

     puts(str1);

puts(str2);

}

翻译一下题目,把第一个字符串从下表m开始赋值给第二个字符串

#include <iostream>

using namespace std;

void strcopy(char *str1, char *str2, int m)

{

    char *p1, *p2;

    p1 = str1 + m; // Blank 4

一个坑点,p1要+m,刚好对应下标为m

    p2 = str2;

    while (*p1)

    {

        *p2 = *p1; // Blank 5

        p1++;      // Blank 6

        p2++;

    }

    *p2 = '\0'; // Ensure the destination string is null-terminated

坑点2,要加’\0‘

}

int main()

{

    int m;

    char str1[80], str2[80];

    gets_s(str1);

    cin >> m;

    strcopy(str1, str2, m); // Blank 7

    puts(str1);

    puts(str2);

    return 0;

}

        struct N {

                 int age;

                 N *next;

        };

        N *head, *p;

        head = new N;

        p = head;

        p->age = 5;     

        p->next = new N;

        p = p->next;

        p->age = 10;

        p->next = NULL;

p此时停留在10这个节点,head则是停留在5

可以让p=head->next

head->next=NULL.

达到了使得10这个节点消失的效果

        //  the following statements is to delete node which age = 10.

        ______【8】______     

        ______【9】______

        delete p;

}

Question 5: Programming ( 5 Points)

Tips: Program readability is very important! Write comments and use functions to reach that goal. If teachers can understand your program well, you could get more scores.

Use a struct to represent the points on the XY-coordinate system. Please write a program to read four vertex coordinates of a quadrilateral(四边形) sequentially, then determine whether the graph composed of the lines of four vertices is a square, rectangle or other quadrilateral. You should use the paraments in the struct to define a function that calculates the distance between two vertices.

For example:

Input four vertex coordinates sequentially:

1 1

1 2

2 2

2 1

Output of the program:

The graph composed of the lines of four vertices is a square.

(或者输出:四个顶点构成的图形为正方形.)

ans

#include <iostream>

#include <cmath>

using namespace std;

// 结构体表示坐标点

struct Point {

    double x;

    double y;

};

// 计算两个点之间的距离

double calculateDistance(Point p1, Point p2) {

    return sqrt(pow(p2.x - p1.x, 2) + pow(p2.y - p1.y, 2));

}

// 判断四边形类型

void determineQuadrilateral(Point p1, Point p2, Point p3, Point p4) {

    double d1, d2, d3, d4;

    // 计算四条边的长度

    d1 = calculateDistance(p1, p2);

    d2 = calculateDistance(p2, p3);

    d3 = calculateDistance(p3, p4);

    d4 = calculateDistance(p4, p1);

    // 判断四边形类型

    if (d1 == d2 && d2 == d3 && d3 == d4) {

        cout << "It is a square." << endl;

    } else if ((d1 == d3 && d2 == d4) || (d1 == d2 && d3 == d4)) {

        cout << "It is a rectangle." << endl;

    } else {

        cout << "It is another type of quadrilateral." << endl;

    }

}

int main() {

    Point p1, p2, p3, p4;

    // 读取四个顶点的坐标

    cout << "Enter coordinates for the first point (x y): ";

    cin >> p1.x >> p1.y;

    cout << "Enter coordinates for the second point (x y): ";

    cin >> p2.x >> p2.y;

    cout << "Enter coordinates for the third point (x y): ";

    cin >> p3.x >> p3.y;

    cout << "Enter coordinates for the fourth point (x y): ";

    cin >> p4.x >> p4.y;

    // 判断四边形类型

    determineQuadrilateral(p1, p2, p3, p4);

    return 0;

}

附上:世间温柔,不过是芳春柳摇染花香,槐序蝉鸣入深巷,白茂叶落醉故乡。

再会

  • 55
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Compiler Construction Experiment 1 Implementing a Scanner for TINY+ You are to write a lexical analyzer/scanner for the language TINY+. Goals 1The input of the scanner is a source code file and the output of the scanner is a stream of tokens. 2Your scanner should go for longest possible match i.e. a string ‘:=’ is to be identified as ‘ass-symbol’ rather than ‘:’ and ‘=’. 3Token is represented as (Kind, Value). We use the following symbols to denote different kinds of tokens KEY denotes reserved words SYM denotes special symbols ID denotes identifiers NUM denotes numeric constants STR denotes string constants 4Check lexical errors: giving meaning error messages and the lines where errors occur. The kinds of lexical errors are: Illegal character, that is, scanner may recognize a character that is not in the alphabet of TINY+, such as $ is an illegal character The right bracket of a STRING is lost, such as ' scanner The right delimiter of a comment is lost, such as: {this is an example Requirements 1Write your program in C or C++ 2This experiment must be finished in 4 periods. You will submit a report and the source code Example output for some TINY+ programs Test1 or and int bool char while do if then else end repeat until read write , ; := + - * / ( ) = a2c 123 'EFG' The scanner should give the outputs: (KEY, or) (KEY, and) (KEY, int) (KEY, bool) (KEY, char) (KEY, while) (KEY, do) (KEY, if) (KEY, then) (KEY, else) (KEY, end) (KEY, repeat) (KEY, until) (KEY, read) (KEY, write) (SYM, ,) (SYM, ;) (SYM, :=) (SYM, +) (SYM, -) (SYM, *) (SYM, /) (SYM, ( ) (SYM, )) (SYM, ) (SYM, =) (ID, a2c) (NUM, 123) (STR, EFG) Test2 {this is an example} int A,B; bool C1, C2, C3; char D; D:= 'scanner'; while A<=B do A:=A*2 end The scanner should give the outputs: (KEY, int) (ID, A) (SYM, ,) (ID, B) (SYM, ;) (KEY, bool) (ID, C1) (SYM, ,) (ID, C2) (SYM, ,) (ID, C3) (SYM, ;) (KEY, char) (ID, D) (SYM, ;) (ID, D) (SYM, :=) (STR, scanner) (SYM, ;) (KEY, while) (ID, A) (SYM, <=) (ID, B) (KEY, do) (ID, A) (SYM, :=) (ID, A) (SYM, *) (NUM, 2) (KEY, end)
Experiment 1 The QuickSort Algorithm 1.Introduction to the quicksort algorithm In order to sort the input data sequence S, we can do like below: 1)Select one number q and then divide the sequence S into three sub-suquences: S1 in which all of elements are less than q, S2 in which all of elements are equal to q, and S3 in which all of elements are larger than q; 2)Then to sort S1 and S3 with the same algorithm using recursive call itself. 2. Experimental Purposes (1)Learn the sorting algorithms. (2)Understand the difference between the quicksort algorithm and other sorting algorithms, such as: insertion sorting algorithm, straight selection algorithm, etc.. (3)Simulate these algorithms using computer with high-level languages. (4)Solve some sorting problem with different sort algorithms. 3. Abstract of Experiment contents Use QuickSort algorithm to sort the array S that has n elements and constructed by the random() function. To compare the result with ones solved by other sorting algorithms, such as Straight selection sort, insert sort, etc., and understand the difference among them and know how to select some better sorting algorithm while solving some sorting problem. 4. Experimental Requirements 1)The template should be used for all kinds of data type, such as: integer, real, double, etc. in the program; 2)Programs should be made by Object-Oriented Programming (OOP) method; 3)The results should be compared with ones of other algorithms, such as: Straight selection sort, insert sort, Heapsort, etc., and draw the graph to find their differences. Figure 1 The difference between quicksort and insertion sort 4)Write down the report in which there should be the execution results of the program. 5. Example code with C++ ………. void myquicksort(int* A, int l,int r) { if(l>=r) return ; int i=l,j=r; int temp; //Use it to divide A into S1, S2,and S3 ……. //Partition S into S1, S2 and S3 here ……. myquicksort(A,l,i-1); //recursive call for the left part
Requirement: I. Query database with SQL Server. (30’, 2’ for each) 1. Create a table named Student using command Create Table. The table structure is as follows: Column Type Length Note ID Varchar 20 Student’s ID Name Varchar 10 Student’s Name Age Int Student’s Age Department Varchar 30 Student’s Dept. 2. Create a table named Course using command Create Table. The table structure is as follows: Column Type Length Note CourseID Varchar 15 Course’s ID CourseName Varchar 30 Course’s Name CourseBefore Varchar 15 Previous Course 3. Create a table named Choose using command Create Table. The table structure is as follows: Column Type Length Note ID Varchar 20 Student’s ID CourseID Varchar 15 Course’s ID Score Dec 5,2 Student’s Score 4. Insert 3 records into table Student using command Insert. ID Name Age Department 00001 ZhangSan 20 Computer Science 00002 LiSi 19 Computer Science 00003 WangWu 21 Computer Science 5. Insert 3 records into table Course using command Insert CourseID CourseName CourseBefore C1 Introduction to Computer - C2 PASCAL Programming Language C1 C3 Data Structure C2 6. Insert 7 records into table Choose using command Insert ID CourseID Score 00001 C1 95 00001 C2 80 00001 C3 84 00002 C1 80 00002 C2 85 00003 C1 78 00003 C3 70 7. Select the students’ ID and Name in Computer Science department using command select. 8. Select the students’ ID, Name, CourseName and Score using command select. 9. Select all students’ Information in descending order of the students’ ID. 10. Select every student’s average score. 11. Select the number of courses a student has chosen. 12. Select the number of students choosing a specific course. 13. Select the students’ ID who have chosen course C1 and got score over 80. 14. Select the students’ ID who have chosen course C2. 15. Select the average age of students in every department. II. Design a MIS for Computer Science college of SCUT. (45’) It is used to manage the information about course

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值