C语言程序设计_题库管理系统
- 格式:doc
- 大小:653.50 KB
- 文档页数:21
《C 语言程序设计》题库吕橙1一、单选题1、能正确表示a和b同时为正或同时为负的逻辑表达式是______。
A:(a>=0||b>=0)&&(a<0|| b<0) B:(a>=0&&b>=0)&&(a<0&&b<0) C:(a+b>0)&&(a+b<=0) D:a*b>0答案:D难度:1知识点:单选题/第四章2、若执行下面的程序时从键盘上输入3和4,则输出是______。
A:14 B:16 C:18 D:20答案:B难度:1知识点:读程序选结果/第四章3、设a、b和c都是int型变量,且a=3、b=4、c=5,则下面的表达式中,值为0的表达式是______。
A:'a'&&'b' B:a<=b C:a||+c&&b-c D:!((a<b)&&!c||1)答案:D难度:1知识点:单选题/第四章4、设a=5、b=6、c=7、d=8、m=2、n=2,执行(m=a>b)&&(n=c>d)后n的值为______。
A:1 B:2 C:3 D:4答案:B难度:1知识点:单选题/第四章第4 章选择题2 吕橙5、设ch是char型变量,其值为A,且有下面的表达式ch=(ch>='A'&&ch<='Z')?(ch+32):ch 上面表达式的值是______。
A:A B:a C:Z D:z答案:B难度:1知识点:单选题/第四章6、下面程序的输出是______。
A:-1 B:0 C:1 D:不确定的值答案:A难度:1知识点:读程序选结果/第四章7、表达式:10!=9的值是______。
A:true B:非零值C:0 D:1答案:D难度:1知识点:单选题/第四章8、有如下程序《C 语言程序设计》题库吕橙3该程序的输出结果是______。
C语言程序设计题库1. 实时温度转换程序题目描述:编写一个实时温度转换程序,要求用户输入一个华氏温度,然后将其转换为摄氏温度并显示出来。
解答:```c#include <stdio.h>int main() {float fahrenheit, celsius;// 获取用户输入的华氏温度printf("请输入一个华氏温度:");scanf("%f", &fahrenheit);// 进行温度转换celsius = (fahrenheit - 32) * 5 / 9;// 显示转换后的摄氏温度printf("转换后的摄氏温度为:%.2f\n", celsius);return 0;}```2. 求两个数的最大公约数和最小公倍数题目描述:编写一个程序,用户输入两个正整数,程序输出这两个数的最大公约数和最小公倍数。
解答:```c#include <stdio.h>// 函数声明:求两个数的最大公约数int getGCD(int num1, int num2) {int temp;while (num1 % num2 != 0) {temp = num1 % num2;num1 = num2;num2 = temp;}return num2;}// 函数声明:求两个数的最小公倍数int getLCM(int num1, int num2) {int gcd = getGCD(num1, num2);return num1 * num2 / gcd;}int main() {int num1, num2;// 获取用户输入的两个正整数printf("请输入两个正整数:");scanf("%d %d", &num1, &num2);// 输出最大公约数和最小公倍数printf("最大公约数:%d\n", getGCD(num1, num2));printf("最小公倍数:%d\n", getLCM(num1, num2));return 0;}```3. 字符串逆序输出题目描述:编写一个程序,用户输入一个字符串,程序将其逆序输出。
银行管理系统c语言程序设计代码以下是一个简单的银行管理系统的C语言程序设计代码示例:```c#include <stdio.h>#include <stdlib.h>struct BankAccount {int accountNumber;char accountHolder[50];float balance;};void createAccount(struct BankAccount *account) {printf("请输入账户号码: ");scanf("%d", &(account->accountNumber));printf("请输入账户持有人姓名: ");scanf("%s", account->accountHolder);printf("请输入账户余额: ");scanf("%f", &(account->balance));printf("账户创建成功!\n");}void deposit(struct BankAccount *account) {float amount;printf("请输入存款金额: ");scanf("%f", &amount);account->balance += amount;printf("存款成功!\n");}void withdraw(struct BankAccount *account) {float amount;printf("请输入取款金额: ");scanf("%f", &amount);if (amount > account->balance) {printf("余额不足,取款失败!\n");} else {account->balance -= amount;printf("取款成功!\n");}}void displayAccount(struct BankAccount *account) {printf("账户号码: %d\n", account->accountNumber);printf("账户持有人姓名: %s\n", account->accountHolder); printf("账户余额: %.2f\n", account->balance);}int main() {struct BankAccount account;int choice;while (1) {printf("\n银行管理系统\n");printf("1. 创建账户\n");printf("2. 存款\n");printf("3. 取款\n");printf("4. 显示账户信息\n");printf("5. 退出\n");printf("请选择操作: ");scanf("%d", &choice);switch (choice) {case 1:createAccount(&account); break;case 2:deposit(&account);break;case 3:withdraw(&account);break;case 4:displayAccount(&account);break;case 5:printf("感谢使用银行管理系统,再见!\n");exit(0);default:printf("无效的选择,请重新输入。
c语言管理系统设计源代码以下是一个简单的C语言管理系统示例,用于管理学生信息。
该系统可以添加、删除、修改和查找学生信息。
c复制代码#include<stdio.h>#include<stdlib.h>#include<string.h>struct student {char name[50];int roll;float marks;};struct student students[100];int count = 0;void add_student() {struct student new_student;printf("Enter name: ");scanf("%s", new_);printf("Enter roll number: ");scanf("%d", &new_student.roll);printf("Enter marks: ");scanf("%f", &new_student.marks);students[count] = new_student;count++;}void delete_student() {int index;printf("Enter index of student to delete: ");scanf("%d", &index);for (int i = index; i < count - 1; i++) {students[i] = students[i + 1];}count--;}void modify_student() {int index;struct student new_student;printf("Enter index of student to modify: "); scanf("%d", &index);printf("Enter new name: ");scanf("%s", new_);printf("Enter new roll number: ");scanf("%d", &new_student.roll);printf("Enter new marks: ");scanf("%f", &new_student.marks);students[index] = new_student;}void find_student() {char name[50];printf("Enter name of student to find: "); scanf("%s", name);for (int i = 0; i < count; i++) {if (strcmp(students[i].name, name) == 0) { printf("Roll number: %d\n", students[i].roll); printf("Marks: %.2f\n", students[i].marks); return;}}printf("Student not found.\n");}int main() {int choice;do {printf("\nMenu:\n");printf("1. Add student\n");printf("2. Delete student\n");printf("3. Modify student\n");printf("4. Find student\n");printf("5. Exit\n");printf("Enter choice: ");scanf("%d", &choice);switch (choice) {case1: add_student(); break;case2: delete_student(); break;case3: modify_student(); break;case4: find_student(); break;case5: exit(0); break; // exit the program here, otherwise the loop will keep running indefinitely, as it is in the do-while loop above. We are not returning, but rather exiting the program completely, so we do not need to return anything. The return value of main is always 0, and this is how the program exits. If you want to return a value other than 0, you can do so like this: return 1; or return -1; or return any other integer value you want to represent an error condition. The operating system will interpret this as the program's exit status. In this case, it will be seen as successful, as it is returning 0. The return value of main is not used for anything in this program, but it can be used in other programs to determine whether the program exited successfully or with an error. For example, if you were writing a shell script that executed this program and needed to know if it was successful or not, you could check the return value of the program and act accordingly. This is a common practice in programming, and it is important to understand how it works so that you can use it effectively in your own programs.。
c语言课程设计报告图书管理系统一、教学目标本课程的目标是使学生掌握C语言的基本语法,熟悉图书管理系统的开发流程,培养学生运用C语言解决实际问题的能力。
具体目标如下:1.知识目标:–掌握C语言的基本语法和数据结构。
–理解图书管理系统的需求和设计原理。
2.技能目标:–能够使用C语言编写简单的程序。
–学会使用C语言实现图书管理系统的功能。
3.情感态度价值观目标:–培养学生的团队协作意识和沟通能力。
–增强学生对计算机科学和编程的兴趣和热情。
二、教学内容本课程的教学内容主要包括C语言的基本语法、数据结构以及图书管理系统的开发。
具体安排如下:1.C语言的基本语法:–变量和数据类型–运算符和表达式–函数和数组–指针和引用2.数据结构:3.图书管理系统的开发:–系统测试和优化三、教学方法本课程采用多种教学方法,以激发学生的学习兴趣和主动性。
具体方法如下:1.讲授法:用于讲解C语言的基本语法和数据结构。
2.案例分析法:通过分析具体的图书管理系统案例,使学生更好地理解系统设计和功能实现。
3.实验法:让学生动手编写程序,巩固所学知识,提高实际操作能力。
4.小组讨论法:鼓励学生分组讨论,培养团队协作意识和沟通能力。
四、教学资源本课程所需的教学资源包括:1.教材:《C语言程序设计》2.参考书:《C Primer Plus》、《数据结构与算法分析》3.多媒体资料:教学PPT、视频教程4.实验设备:计算机、网络设备以上教学资源将用于支持教学内容和教学方法的实施,丰富学生的学习体验。
五、教学评估本课程的评估方式包括平时表现、作业、考试等。
评估方式应客观、公正,能够全面反映学生的学习成果。
具体安排如下:1.平时表现:包括课堂参与度、提问回答、小组讨论等,占总评的20%。
2.作业:包括编程练习和理论作业,占总评的30%。
3.考试:包括期中和期末考试,占总评的50%。
期中和期末考试将涵盖C语言基本语法、数据结构以及图书管理系统的开发内容。
第1次客观题作业一、单选题(共30题,每题3分)1 .下面表示正确的是__A___。
A.C语言中的逗号是一种运算符B.在C语言中,一行只能有一个语句C.C中的变量不区分大小写D.c中的关键字可以做为变量名2 .字符型常量在内存中存放的是__A____代码值。
A.ASCII B.二进制C.十进制D.八进制3 .以下不正确的C语言标识符是(C )。
A.AB1 B._ab3 C.4ab D.a2_b4 .以下运算符中优先级最低的运算符是_D____。
A.&& B.& C.|| D.=5 .在C语言中,要求运算数必须是整型的运算符是___A___。
A.% B./ C.< D.!6 . C语言程序的基本单位是__C_____。
A.程序行B.语句C.函数D.字符7 .将高级语言编写的程序翻译成目标程序的是___B____程序。
A.解释程序B.编译程序C.汇编程序D.源程序8 .以下选项中,与k=n++完全等价的表达式是__A___。
A.k=n,n=n+1 B.n=n+1,k=n C.k=++n D.k+=n+19 .下列(A )不属于结构化程序设计的循环结构。
A.For B.While C.if-else D.do-while10 .以下叙述中错误的是__A___。
A.用户所定义的标识符允许使用关键字B.用户所定义的标识符应尽量做到“见名知意C.用户所定义的标识符必须以字母或下划线开头D.用户定义的标识符中,大、小写字母代表不同标识11 .若有输入语句scanf( %d%d%d,&x,&y,&z);则不能使x值为5,y值为6,z值为7的输入是__A____。
A.5,6 ,7 B.5回车换行 6 7 C.5 6 7 D.5,6,712 .若i,j已定义为int类型,则下程序段中内循环体的总的执行次数是( B )。
for (i=3;i>0;i--) for (j=0;j<=4;j++){...}A.12 B.15 C.16 D.2013 .下列选项中,合法的C语言关键字是_D___。
《c语言程序设计》试题库及答案一、选择题1. 下列哪个选项是C语言的标准库函数?A. printfB. scanfC. mainD. All of the above答案:D2. C语言中,用于定义字符串的字符数组的语法是什么?A. char str[] = "Hello";B. char str[] = {"Hello"};C. char str = "Hello";D. char str[] = 'Hello';答案:A3. 在C语言中,以下哪个关键字用于定义一个函数?A. intB. functionC. defD. void答案:A二、填空题1. 在C语言中,定义一个整型变量的正确方式是:________。
答案:int variable_name;2. C语言中,用于计算两个数的和的运算符是:______。
答案:+3. 如果要在C语言中声明一个指向整型的指针,应该使用:________。
答案:int *pointer_name;三、简答题1. 请简述C语言中数组和指针的区别。
答案:数组是一组相同类型的元素的集合,可以通过索引访问每个元素。
指针是一个变量,它存储了另一个变量的内存地址。
数组名可以被用作指向数组首元素的指针,但数组本身是一个固定大小的实体,而指针可以被重新赋值为其他地址。
2. 解释C语言中的结构体(struct)是什么?答案:结构体是一种用户定义的数据类型,它允许将不同的数据类型组合成一个单一的数据结构。
它使得可以创建包含多种数据类型的复杂数据结构。
四、编程题1. 编写一个C语言程序,实现计算两个整数的和,并输出结果。
```c#include <stdio.h>int main() {int num1, num2, sum;printf("Enter two integers: ");scanf("%d %d", &num1, &num2);sum = num1 + num2;printf("The sum is: %d\n", sum);return 0;}```2. 编写一个C语言程序,实现将一个字符串反转,并输出结果。
程序设计基础课程设计报告班级:计算机科学与技术1103班*名:*******: ***完成日期: 2012年9月6日(题目)1.设计题目与要求(简要介绍课程设计题目内容与要求。
)1设计内容要求输入试题(仅限选择题和填空题)基本信息,实现试题浏览.,查询,修改功能,并将数据保存至文本文件。
2要求功能完善,界面友好。
2.算法设计与描述(要求有相关流程图)算法设计与描述(描述算法设计、实现过程。
)1.提供可操作的主菜单:输出主菜单,用户可根据菜单来选择操作。
根据客户输入的选项来运行不同的功能,运行不同的函数。
2.。
试题信息的录入函数:按照提示输入题的题号,题目内容,并提示用户是否继续录入,每输入一个记录,全局变量n就自增,最后最为函数的返回值返回。
3.保存试题信息函数:将文件的所有数据通过fprintf来写入指定文本文档,完成后关闭文件,没有返回值4. 载入试题信息函数:通过fopen函数打开指定文件,通过fscanf来读取文件里的数据,最后返回记录数,避免了每次打开时都要输入数据的麻烦。
5. 查询记录函数:细分为按题号,题目两种方式来进行查询记录,并能对查询记录不存在进行提示。
遍历所有结构体找出符合的输出。
6. 修改记录函数:首先判断用户要修改的试题序号是否存在,进行相应的系统提示,然后遍历所有记录找出符合的,按照提示依次进行修改项目,返回记录值不变(没增加也没减少)。
7. 删除记录函数:首先判断用户要删除的试题序号是否存在,进行相应的系统提示,然后遍历所有记录找出符合的删除,冰讲后面的所有数据向前移动一个位置,记录数减一并返回。
主要流程图(用N—S图描述。
)1,、输入函数2、保存函数3、载入函数4、查询函数5、修改函数6、删除函数3.设计软硬件环境硬件设备系统:Microsoft Windows XP Professional 版本 2002机型:Inter ® Core™2 Duo CPU E8400 @ , GB内存软件设备 Microsoft Visual C++ 应用程序调试4.源程序代码清单#include<>#include<>#include<>typedef struct{char tihao[10]; 题目的输入│ \n");printf("\t\t\t │ 2. 题目的浏览│ \n");printf("\t\t\t │ 3. 题目信息更改│\n"); 题目信息查询│ \n");printf("\t\t\t │ 5. 题目文件操作│\n"); 退出管理系统│ \n");printf("\t\t\t └───────────┘ \n");printf("\t\t\t ============================ \n");printf("\n\t\t请您选择(0-5):");c=getchar();}while(c<'0'||c>'5');return(c-'0');}void tihaosort(Data dat[],int n) ihao,da[j].tihao)>0){temp=da[i];da[i]=da[j];da[j]=temp;}printf("\t\t========排序成功========\n");}void SaveText(Data dat[],int n) ihao,dat[i].timu);fprintf(fp,"\r\n"); /*将换行符号写入文件*/}fclose(fp);}int LoadText(Data dat[]) ihao,dat[i].timu); /*按格式读入记录*/fclose(fp);return n; /*返回记录数*/}int Charu(Data dat[],int n) ihao,==0){printf("\t-------该记录已存在,请重新输入!-------\n");system("pause");system("cls");break;}}}while(strcmp(dat[k].tihao,==0);printf("\t题目:");scanf("\t%s",;printf("\t请输入插入位置的题号:");scanf("\t%s",s); /*输入插入位置的题号*/while(strcmp(dat[i].tihao,s)!=0&&i<n) i++;if(i==n){printf("\t------------题库中没有记录,请查询后再操作!-------------\n");return n;}for(i=0;strcmp(dat[i].tihao,s)!=0;i++) ;printf("\n\t\t***********插入成功!************\n");for(j=n-1;j>=i;j--) /*从最后一个结点开始向后移动一条*/{strcpy(dat[j+1].tihao,dat[j].tihao); /*当前记录的题号拷贝到后一条*/strcpy(dat[j+1].timu,dat[j].timu);}strcpy(dat[i].tihao,; /*将新插入记录的题号拷贝到第i个位置*/strcpy(dat[i].timu,;n++; /*记录数加1*/return n;}int Shuru(Data dat[],int n) ihao);printf("\t题目:");scanf("\t%s",dat[n+i].timu);printf("\n\t是否继续添加(Y/N)");scanf("\t%c",&ch);i++;}return (n+i); ihao,dat[i].timu);/*按格式输出*/printf("───────────────────────────────\n");}system("pause");}int Shanchu(Data dat[],int n) ihao,s)!=0&&i<n) i++; /*查找要删除的记录题号*/if(i==n){printf("\t题库中没有此题!\n");return(n);}for(j=i;j<n-1;j++) imu,dat[j+1].timu);strcpy(dat[j].tihao,dat[j+1].tihao);}printf("\t\t\t已经成功删除!\n");return(n-1);}void Chazhao(Data dat[],int n) ihao,s)!=0&&i<n) i++;if(i==n){printf("\t题库中没有此题!\n");return;}printf("\t此题内容\n");printf("\t%5s\n",dat[i].timu);} ;}void Biangeng(Data dat[],int n) ihao,s)!=0&&i<n) i++;if(i==n){printf("\t题库中没有此题!\n");return;}printf("\t题号:");scanf("\t%s",dat[i].tihao);printf("\t题目:");scanf("\t%s",dat[i].timu);printf("\n\t修改成功!");}void CopyText() ihao,temp[i].timu);fprintf(fc,"%-8s%-6s",temp[i].tihao,temp[i].timu);fprintf(fc,"\r\n"); /*写入换行符*/ }fclose(fp); /*关闭源文件*/ fclose(fc); /*关闭目标文件*/ printf("\t\t您已成功复制文件!\n");}/* 主函数 */void main(){int n=0;for(;;){switch(menu_select()){case 1:system("cls");n=Shuru(da,n);break;case 2:system("cls");int k;printf("\t\t\t ======题库信息管理系统====== \n");printf("\t\t\t ┌──────────┐ \n");printf("\t\t\t │1.显示全部题目│ \n");printf("\t\t\t │2.按题号排序信息│ \n");printf("\t\t\t │0.返回上一级菜单│ \n");printf("\t\t\t └──────────┘ \n");printf("\t\t\t ============================ \n");printf("\n\t\t请选择:");scanf("%d",&k);switch(k){case 1: 库信息的修改│\n");printf("\t\t\t │2.题库信息的删除│\n");printf("\t\t\t │3.题库信息的插入│\n");printf("\t\t\t │0.返回│\n");printf("\t\t\t └──────────┘\n");printf("\t\t\t ========================== \n");printf("\n\t\t请选择:");scanf("%d",&m);switch(m){case 1:system("cls");Biangeng(da,n);printf("\t");system("pause");break;case 2:system("cls");n=Shanchu(da,n); /*删除记录*/ printf("\t");break;case 3:system("cls");n=Charu(da,n); 库信息的载入│\n"); printf("\t\t\t │2.题库信息的保存│\n");printf("\t\t\t │3.题库信息的复制│\n");printf("\t\t\t │0.返回│\n");printf("\t\t\t └──────────┘\n");printf("\t\t\t ========================== \n");printf("\n\t\t请选择:");scanf("%d",&x);switch(x){case 1:n=LoadText(da);printf("\t\t您已经成功的将题目导入到题库!\n");printf("\t");system("pause");break;case 2:printf("\t\t=========题库的保存=========\n");SaveText(da,n);printf("\n\t\t保存成功\n");printf("\t");break;case 3:CopyText(); /*保存数据*/printf("\t");system("pause");break;case 0:;}break;case 0:printf("\n\t\t\t感谢您的使用,再见!\n");exit(0);}}}5.程序运行结果(可截屏程序运行界面。