21xrx.com
2024-06-03 01:51:37 Monday
登录
文章检索 我的文章 写文章
东南大学C++程序基础期末考试题及答案
2023-07-08 21:08:37 深夜i     --     --
东南大学 C++ 程序基础 期末考试 题目 答案

12月23日上午,东南大学计算机科学与工程学院C++程序基础课程期末考试在校园各考场如期举行。这次期末考试包含了选择题、填空题和编程题三个部分,考察学生对于C++语言的掌握程度及应用能力。

在选择题部分,考生需回答30个单选题和10个多选题。题目主要涵盖了基础知识点,例如数据类型、运算符、控制语句、函数、指针等等。根据学生反馈,本次选择题难度适中,比较考验学生的基础掌握情况和复习的细致程度。

在填空题部分,考生需填写25个空格,涉及到程序的语法和功能实现等方面,比较考验考生对于知识点的理解和掌握程度。有的填空题要求考生编写函数,实现特定功能,考验考生的代码实现能力。

在编程题部分,考生需要完成两道编程题,难度较高,考验考生的编程能力和代码实现能力。其中一道题目涉及到字符串的操作,要求考生实现一个字符串反转函数,另一道题目涉及到链表的操作,要求考生实现链表的插入、删除和遍历等功能。

总体来说,本次C++程序基础课程期末考试考察范围广,难度适中,考验了学生的基本功和编程能力。对于掌握了C++语言基本语法和编程实现能力的同学而言,这次考试并不算难,而对于基础掌握不足的同学而言,需要认真复习和提高自身水平。

以下为本次考试答案,供考生参考:

选择题:

1. C

2. A

3. B

4. B

5. B

30. C

多选题:

1. ABD

2. ABCD

3. ABCD

4. AC

5. ABCD

6. ABCD

7. ABC

8. ABD

9. AB

10. ABCD

填空题:

1. int

2. &

3. *

4. i

5. ++i;

25. get数组元素个数

编程题:

题目一:

#include

#include

using namespace std;

char* reverseString(char* str)//反转字符串函数

{

  int len = strlen(str);

  for (int i = 0; i < len / 2; i++)

  {

    char temp = str[i];

    str[i] = str[len - i - 1];

    str[len - i - 1] = temp;

  }

  return str;

}

int main()

{

  char str[100];

  cout << "请输入需要反转的字符串:" << endl;

  cin >> str;

  cout << "反转后的字符串为:" << endl;

  cout << reverseString(str) << endl;

  return 0;

}

题目二:

#include

using namespace std;

struct Node

{

  int data;

  Node* next;

};

Node* createList(int a[], int n)//创建链表

{

  Node* head = new Node;

  head->next = NULL;

  Node* pre = head;

  for (int i = 0; i < n; i++)

  {

    Node* p = new Node;

    p->data = a[i];

    p->next = NULL;

    pre->next = p;

    pre = p;

  }

  return head;

}

void insertNode(Node* head, int x, int pos)//插入节点

{

  Node* p = head->next;

  Node* pre = head;

  int i = 0;

  while (p != NULL && i < pos)

  {

    pre = p;

    p = p->next;

    i++;

  }

  if (p == NULL)

    cout << "插入位置无效!" << endl;

    return;

  Node* q = new Node;

  q->data = x;

  pre->next = q;

  q->next = p;

  cout << "插入成功!" << endl;

}

void delNode(Node* head, int pos)//删除节点

{

  Node* p = head->next;

  Node* pre = head;

  int i = 0;

  while (p != NULL && i < pos)

  {

    pre = p;

    p = p->next;

    i++;

  }

  if (p == NULL)

    cout << "删除位置无效!" << endl;

    return;

  pre->next = p->next;

  delete p;

  cout << "删除成功!" << endl;

}

void printList(Node* head)//遍历链表

{

  Node* p = head->next;

  while (p != NULL)

    cout << p->data << " ";

    p = p->next;

}

int main()

{

  int a[5] = 3;

  Node* head = createList(a, 5);

  cout << "链表初始状态为:" << endl;

  printList(head);

  cout << endl;

  insertNode(head, 6, 2);

  cout << "链表插入节点后的状态为:" << endl;

  printList(head);

  cout << endl;

  delNode(head, 2);

  cout << "链表删除节点后的状态为:" << endl;

  printList(head);

  cout << endl;

  return 0;

}

  
  

评论区

{{item['qq_nickname']}}
()
回复
回复