大连理工大学C语言第二次上机第二次作业
- 格式:docx
- 大小:295.70 KB
- 文档页数:12
A1.已知大写字母A的ASCII码值是65,小写字母a的ASCII码是97,则用八进制表示的字符常量'\101'是()。
A、字符AB、字符aC、字符eD、非法的常量C2.下列程序段的输出结果为()。
float k=0.8567; printf("%4.1f%%",k*100);A、85.6%B、85.6%%C、85.7%D、.857A3.下面的scanf函数输入数据,使得a=10,b=15,s1='S',s2='s',x1=1.5,x2=-3.75,x3=67.8, 正确的键盘输入方法是( ).(用"[CR]"表示回车,U表示空格)main(){int a,b;float x1,x2,x3;char s1,s2;scanf("%5d%5d%c%c%f%f%*f%f",&a,&b,&s1,&s2,&x1,&x2,&x3);}A、10UUU15Ss1.5U-3.75U+1.5U67.8[CR]B、10UUU15USUs1.5U-3.75U+1.5U67.8[CR]C、10UUU15USUsU1.5U-3.75U+1.5U67.8[CR]D、10UUU15Ss1.5U-3.75U+1.5,67.8[CR]A4. C语言的if语句中,用作判断的表达式为( )。
A、任意表达式B、算术表达式C、逻辑表达式D、关系表达式A5以下程序的输出结果是:( )main(){int m=5;if(m++>5) printf("%d\n",m);else printf("%d\n",m--);}A、6B、5C、7D、4C6以下for循环的执行次数是 for(x=0,y=0;(y=123)&&(x<4);x++);()。
大连理工大学C++程序设计大作业班级:111111111姓名:暗暗暗暗暗暗暗暗学号:1111111111邮箱:1111111111111111任课教师:赵国辉上交时间:2013.7.22目录1.第一次上机作业 (3)2.第二次上机作业 (6)3.第三次上机作业 (10)4.第四次上机作业 (15)5.结课大作业 (18)6.课堂总结 (48)1. 第一次上机作业1.1作业要求1.整型和浮点型的二进制表示2.一个整数的二进制(64位)转换成十进制表示。
1.2 核心代码说明整型和浮点型的二进制表示#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <queue>#include <stack>using namespace std;void getint(int x){stack<int>s;while(x){s.push(x&1);x>>=1;}while(!s.empty()){cout<<s.top();s.pop();}} //将整型转换成二进制函数void getfloat(float y){queue<int>q;int x=(int)y;getint(x);y-=x; //将浮点型转换成二进制函数if(!y) return ;putchar('.');while(y){y*=2.0;if(y>=1.0){q.push(1);y-=1.0;}else q.push(0);}while(!q.empty()){cout<<q.front();q.pop();}}int main(){int x;float y;cin>>x;//输入一个整数getint(x);cout<<endl;cin>>y;//输入一个浮点数getfloat(y);cout<<endl;return 0;}一个整数的二进制(64位)转换成十进制表示。
大连理工大学c语言大作业第一篇:大连理工大学c语言大作业程序设计大作业总结报告——<东北大馅饺子馆>的点餐/帐目信息管理系统选题意义;餐厅账目繁多,通过本系统可以实现餐厅管理的自主化。
更加适应这个信息化的社会。
通过对账目、订单的管理与排序。
也能使餐厅管理者更加直观地看出产品之间的优劣与受众。
使其能够更好的调动资源,达到餐厅的快速发展目的。
设计方案;1)任务分析该系统应包括两大界面—用户界面和管理界面。
用户界面包括用户点餐功能并将用户点餐信息存入账单文件中。
管理界面包括记录饺子的单价,库存等信息并将这些信息按一定规律排列供管理者参考,还要记录每天的收入与库存消耗。
2)系统组成框图系统组成如下图所示,点餐/帐目信息管理系统中任务调度模块是信息管理的指挥中心,所有的功能模块均通过该模块集中管理和调用。
数据文件是用于将改变的记录随时保存起来,I/O交互模块是指数据按键和控制按键的响应操作。
数据按键是窗口的输入输出。
系统平台I/O交互任务调度数据文件添加账目查询账目查询原料销量排序当天收入功能模块设计;本管理系统开发的过程中成功地完成很多函数的编写,而且全部通过程序调试。
下面针对与该系统相关的主要功能函数的编写思路和实现方法作总结。
1)数据描述与数据文件(1)数据描述;系统中共定义了三种结构体分别是struct list(账单信息)、struct dump(原材料信息)、struct system(管理信息)其中账单信息成员定义如下; struct list/*账单信息 */ { int num;/*编号*/ intmonth;/*月份*/ int date;/*日期*/ int table;/*桌号*/ int people;/*人数*/ int add;/*收款金额*/ };原材料信息;struct dump/*原材料信息*/ { int num;/*编号*/ char a[40];/*名称*/ int price;/*单价*/ int quantity;/*库存*/ };管理信息;struct system { struct dump data;/*点餐*/ int cash;/*收款*/ int sale;/*销量*/ int p;/*人数*/ };(2)数据文件;共定义四个数据文件;记录编号的文件count、记录原料的文件dumplings、记录账单的文件customer、数据处理文件system。
2022年大连理工大学公共课《C语言》科目期末试卷B(有答案)一、填空题1、设有一输入函数scanf("%d”,k);它不能使float类型变量k得到正确数值的原因是_______未指明变量k的地址和_______格式控制符与变量类型不匹配。
2、结构化程序由________、________ 、________ 3种基本结构组成。
3、在C语言中,输入操作是由库函数________完成的,输出操作是由库函数________完成的。
4、若有定义语句:int x=3,y=2;float a=2.5,b=3.5;则表达式(x+y)%2+(int)a/(int)b的值为_______。
5、若有定义语句:int b=7;float a=2.5,c=4.7;则表达式a+(int)(b/3*(int)(a+c)/2)%4的值为_______6、设有char a,b;若要通过a&b运算屏蔽掉a中的其他位,只保留第2和第8位(右起为第1位),则b的二进制数是_______。
7、函数swap(int x,inty)可完成对x和y值的交换。
在运行调用函数中的如下语句后,a[0]和a[1]的值分别为_______,原因是_______。
a[o]=1;a[1]=2;swap(a[o],a[1]);8、下面程序段将输出computer。
请填空。
char c[]="It is a computer";for(i=0;_______;i++){_______;printf("%c",c[j]);}9、下面程序段的运行结果是_______。
int i=5;char c[6]="abcd";do{c[i]=c[i-1];}while(--i>0);puts(c);10、以下程序段通过移动指针变量m,给如图9-7所示连续动态存储单元赋值。
请填空。
(假设程序段中的所有变量均已正确说明。
~计算机二级c 语言上机题库及答案内部资料,切勿外传!.第1 套填空题请补充FUN 函数,FUN 函数的功能是求10 的阶乘。
注意:部分源程序给出如下。
请勿改动主函数main 和其他函数中的任何内容,仅在fun 函数的横线上填入所编写的若干表达式或语句。
试题程序:#include <stdio.h>long fun(int n){if ( 1 )return (n*fun( 2 ));return 3 ;}main(){printf("10!=%ld\n", fun(10));}第1 处填空:n>1 或1<n第2 处填空:n-1第3 处填空:1 或11 或1L改错题下列给定程序的功能是:读入一个整数K(2〈=K〈=10000),打印它的所有因子(即所有为素数的因子)。
例如,若输入整数2310,则应输出:2、3、5、7、11。
请改正程序中的错误,使程序能得出正确的结果。
注意:不要改动main 函数,不得增行或删行,也不得更改程序的结构!试题程序:#include <conio.h>#include <stdio.h>/********found********/IsPrime(int n);{int i, m;m = 1;/********found********/for (i=2; i<n; i++)if !(n%i){m = 0;break;}return(m);}main(){int j, k;printf("\nplease enter an integer number between 2and 10000:");scanf("%d", &k);printf("\n\nThe prime factor(s) of %d is(are):", k);for (j=2; j<k; j++)if ((!(k%j)) && (IsPrime(j)))printf(" %4d,", j);printf("\n");}第1 处:Isprime(int n);应改为Isprime(int n)第2 处:if !(n%i)应该为if(!(n%i))编程题M 个人的成绩存放在score 数组中,请编写函数fun,它的功能是:返回低于平均分的认输,并将低于平均分的分数放在below 所指的数组中。
大连理工大学软件学院数据库第二次上机答案1.select course_idfrom sectiongroup by course_idhaving count (distinct year)>1select course.course_id , titlefrom section join course on section.course_id = course.course_id where year = '2010' and semester = 'spring' and section.course_id in (select course_idfrom sectiongroup by course_idhaving count (distinct year)>1)with c_2010 as (select course_idfrom sectionwhere year = '2010' and semester = 'spring'and course_id in (select course_idfrom sectiongroup by course_idhaving count (distinct year)>1)),ins_sla as(select course_id ,sum(salary)as sum_sal , count (teaches.id) as ins_cntfrom teaches join instructor on teaches.id = instructor.idwhere semester = 'spring' and year = '2010'and course_id in (select course_id from c_2010)group by course_id,sec_credit_hr as (select time_slot_id ,sum (((end_hr - start_hr)*60+ end_min-start_min)/50)as cred_hrfrom time_slotgroup by time_slot_id ),course_hr as (select course_id , cred_hrfrom section join sec_credit_hr on section.time_slot_id = sec_credit_hr.time_slot_idwhere semester = 'spring' and year = '2010'and course_id in (select course_id from c_2010))select course.course_id, title , cred_hr,sum_salfrom ins_sla join course_hr on ins_sla.course_id = course_hr.course_idjoin course on ins_sla.course_id= course.course_id2,course takes student sectionselect * from sectionselect name ,takes.course_id , takes.semester ,takes.year , takes.sec_id ,titlefrom student left join takes on student.id = takes.idleft join section on takes.course_id = section.course_idand takes.sec_id= section.sec_idand takes.semester= section.semesterand takes.year= section.yearfull join course on section.course_id = course.course_idselect * from takesselect count(*)from takeswhere grade = 'F' and id = '45678'select count (*)from takeswhere grade = 'F' and id in (select idfrom studentwhere dept_name in (select dept_name from student where id = '45678' ))select count (*)from takeswhere exists (select *from student as s join student as ton s.dept_name= t.dept_namewhere s.id = takes. id and t.id = '45678') and grade = 'F'select id ,name ,dept_name ,(select count(*)from takeswhere grade = 'F' and id = student.id)as fail ,(select count (*)from takeswhere grade = 'F' and id in (select idfrom student as s1where dept_name in (select dept_name from student as s2 where id = student.id ))) as all_failfrom student4.2??ˉ?éò?ó?not in ±íê?select distinct takes.idfrom instructor join teaches on instructor.id = teaches.idjoin takes on takes.course_id = teaches.course_idand takes.sec_id=teaches.sec_idand takes.semester = teaches.semesterand takes.year = teaches.yearwhere instructor.dept_name= '?ú1|?§?o'μ?μDT?ú1|?§?oà?ê|?ù?ìè?23ìμ??§éúwith stu_all_id as (select idfrom studentwhere not exists ((select course_idfrom teaches join instructor on instructor.id = teaches.id where dept_name= '?ú1|?§?o')except(select course_idfrom takeswhere takes.id = student.id and grade is not null )))select distinct student.id ,/doc/c612295375.html, , count (takes.course_id) from instructor join teaches on instructor.id = teaches.idjoin takes on takes.course_id = teaches.course_idand takes.sec_id=teaches.sec_idand takes.semester = teaches.semesterand takes.year = teaches.yearjoin student on student.id= takes.idwhere instructor.dept_name= '?ú1|?§?o'and student.id not in (select id from stu_all_id)group by student.id ,/doc/c612295375.html,5.select * from courseselect section.course_id, course.title,section.sec_id,section.semester,section.year from section join course on section.course_id = course.course_id where not exists (select * from takes where takes.course_id = section.course_idand takes.sec_id = section.sec_idand takes.semester = section.semesterand takes.year = section.year)and not exists (select * from teaches where teaches.course_id = section.course_idandteaches.sec_id = section.sec_idandteaches.semester = section.semesterand teaches.year = section.year)上一页下一页。
重要说明:本题库为从题中一题一题复制出来工作量大,而且有许多表达式无法在word中快速表示出来(这样会加大工作量)故而省略,或者表达错位,有的地方可能或者肯定会有错,我相信准备参加C语言二级考试的同学应当能够对照参考答案看出来,这是最新版最完整考试题库,相信大家一定都能通过!第一套程序填空给定程序中,函数fun的功能是:将形参n所指变量中,各位上为偶数的数去除,剩余的数按原来从高位到低位的顺序组成一个新的数,并通过形参指针n传回所指变量。
如输入一个数:27638496,新的数为729第一空:{ t=*n%10;第二空:if(t%2!=0)第三空:*n=x;2.程序修改给定程序modi1.c中函数fun的功能是:计算n!。
例如,给n输入5,则输出120.000000。
double fun(int n ){ double result=1.0;/*****found******/if(n==0)return 1.0;while(n>1&&n<170)/*****found******/result*=n--;return result;}程序设计请编写一个函数fun,它的功能是:将一个数字字符串转换为一个整数(不得调用C语言提供的将字符串转换为整数的函数)。
例如,若输入字符串“-1234”,则函数把它转换为整数值-1234。
long fun(char *p){int i,len,t;long x=0;len=strlen(p);if(p[0]==’-‘){ t=-1;len--;p++;}else t=1;while(*p)x=x*10-48+(*p++);return x*t;}第二套1. 给定程序中,函数fun的功能是将形参给定的字符串、整数、浮点数写到文本文件中,再用字符方式从此文本文件中逐个读入并显示在终端屏幕上。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
c语言程序设计上机答案C语言程序设计是一门实践性很强的课程,上机练习是掌握C语言编程技能的重要环节。
以下是一些常见的C语言上机练习题目及其参考答案,供学习者参考。
1. 打印“Hello, World!”```c#include <stdio.h>int main() {printf("Hello, World!\n");return 0;}```2. 计算两个数的和```c#include <stdio.h>int main() {int a, b, sum;printf("请输入两个整数:");scanf("%d %d", &a, &b);sum = a + b;printf("%d + %d = %d\n", a, b, sum);return 0;}```3. 判断一个数是否为素数```c#include <stdio.h>#include <math.h>int isPrime(int n) {if (n <= 1) return 0;for (int i = 2; i <= sqrt(n); ++i) { if (n % i == 0) return 0;}return 1;}int main() {int num;printf("请输入一个整数:");scanf("%d", &num);if (isPrime(num)) {printf("%d 是素数。
\n", num);} else {printf("%d 不是素数。
\n", num); }return 0;}```4. 计算圆的面积```c#include <stdio.h>#include <math.h>double calculateArea(double radius) {return M_PI * radius * radius;}int main() {double radius, area;printf("请输入圆的半径:");scanf("%lf", &radius);area = calculateArea(radius);printf("半径为 %f 的圆的面积是:%f\n", radius, area); return 0;}```5. 字符串反转```c#include <stdio.h>#include <string.h>void reverseString(char str[]) {int length = strlen(str);for (int i = 0; i < length / 2; ++i) {char temp = str[i];str[i] = str[length - i - 1];str[length - i - 1] = temp;}}int main() {char str[100];printf("请输入一个字符串:");scanf("%s", str);reverseString(str);printf("反转后的字符串是:%s\n", str);return 0;}```6. 计算阶乘```c#include <stdio.h>unsigned long long factorial(int n) {if (n == 0) return 1;return n * factorial(n - 1);}int main() {int num;printf("请输入一个非负整数:");scanf("%d", &num);printf("%d 的阶乘是:%llu\n", num, factorial(num)); return 0;}```7. 排序算法(冒泡排序)```c#include <stdio.h>void bubbleSort(int arr[], int n) {for (int i = 0; i < n - 1; ++i) {for (int j = 0; j < n - i - 1; ++j) { if (arr[j] > arr[j + 1]) {int temp = arr[j];arr[j] = arr[j + 1];arr[j + 1] = temp;}}}}int main() {int arr[] = {64, 34, 25, 12, 22, 11, 90}; int n = sizeof(arr) / sizeof(arr[0]);bubbleSort(arr, n);printf("排序后的数组是:\n");for (int i = 0; i < n; ++i) {printf("%d ", arr[i]);}printf("\n");return 0;}```8. 寻找最大值```c#include <stdio.h>int findMax(int arr[], int n) {int max = arr[0];for (int i = 1; i < n; ++i) {if (arr[i] > max) { max = arr[i]; }}return max;。