大连理工大学C语言第二次上机第二次作业

合集下载

大连理工大学c语言上机模拟题1

大连理工大学c语言上机模拟题1

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++大作业

大连理工大学c++大作业

大连理工大学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语言题库(12套)

(完整版)大连理工大学C语言题库(12套)
{
/*********Begin**********/
/********** End **********/
}
main()
{
int n,a[100],i,num;
void TestFunc();
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
num=average_num(a,n);
12.数组名可以作为函数的实参和形参.Y
13.一个include命令只能指定1个被包含的文件。y
14.若p为指针变量,a为数组名,则a-p是合法的表达式.y
15.在程序中定义了一个结构体类型后,可以多次用它来定义具有该类型的变量。Y
16.C语言中,关闭一个文件就删除了这个文件.N
对对错错错对对对对对错对对对对错
printf("the num is:%d\n",num);
TestFunc();
}
void TestFunc()
{
FILE *IN,*OUT;
int n;
int i[10];
int o;
IN=fopen("in.dat","r");
if(IN==NULL)
{
printf("Read File Error");
}
OUT=fopen("out.dat","w");
if(OUT==NULL)
{
printf("Write File Error");
}

大连理工大学c语言大作业

大连理工大学c语言大作业

大连理工大学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(有答案)

2022年大连理工大学公共课《C语言》科目期末试卷B(有答案)

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语言上机题库及答案(100套)

计算机二级C语言上机题库及答案(100套)

~计算机二级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)上一页下一页。

大连理工大学C语言第二次上机第二次作业

大连理工大学C语言第二次上机第二次作业
int main()
{
int a,b,i;
double c,d,a1,b1;
srand(time(NULL));
a = rand()%10;
b = rand()%10;
i = rand()%4;
switch(i)
{
case 0:
c = a + b;
printf("%d+%d= ",a,b);
break;
代码:
#include <stdio.h>
int main()
{
int year,month,day;
scanf("%d%d%d",&year,&month,&day);
if((day==31)&&(month==12))
{
year += 1;
month = 1;
day = 1;
}
else if((day==31)&&(month!=12))
SUN MON TUE WED THU FRI SAT
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 3031
Would you like to display another month (y/n) ? y
{
n++;
Xiang = pow(x,n)/JieCheng(n);
e = e + Xiang;
}
printf("%.4f",e);
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
例:自动生成3+9= 12(用户输入结果后回车),显示Correct!
代码:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int a,b,i;
double c,d,a1,b1;
srand(time(NULL));
a = rand()%10;
{
int i=1,n=1,h,day,st;
switch (mon)
{
case 1:h=7;day=31;break;
case 2:h=31;day=28;break;
case 3:h=31+28;day=31;break;
case 4:h=31+28+31;day=30;break;
case 5:h=31+28+31+30;day=31;break;
break;
case 3:
a1 = a;
b1 = b;
c = a1/b1;
c = (int)(c*100+0.5)/100.0;
printf("保留两位小数\n%d/%d= ",a,b);
break;
}
scanf("%lf",&d);
d = (int)(d*100)/100.0;
if (c==d) printf("\nRight!\n");
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Would you like to display another month (y/n) ? N
代码:
#include <stdio.h>
#include <stdlib.h>
void print_days(int mon)
Enter month in 2017to display calendar (1-12):8
****************************************************
SUN MON TUE WED THU FRI SAT
1 2 3 4 5
6 7 8 9 10 11 12
}
}
else if ((day==29)&&(month=2))
{
month = month + 1;
day = 1;
}
else if ((day==28)&&(month=2))
{
if((year%4 == 0 && year%100!=0)||(year%400 == 0)) day = day + 1;
{
month += 1;
day = 1;
}
else if(day==30)
{
if(month==12||month==10||month==8||month==7||month==5||month==3||month==1)
{
day = day+1;
}
else
{
month = month + 1;
day = 1;
default:break;
}
printf("****************************************************\n");
printf("SUN\tMON\tTUE\tWED\tTHU\tFRI\tSAT\n");
st = h % 7;
switch(st)
{
case 1:printf("");break;
19 20 21 22 23 24 25
26 27 28 29 3031
Would you like to display another month (y/n) ? y
Enter month in 2017to display calendar (1-12): 13
ERROR--- Enter month in range of (1-12)!
case 10:h=31+28+31+30+31+30+31+30;day=31;break;
case 11:h=31+28+31+30+31+30+31+31+30+31;day=30;break;
case 12:h=31+28+31+30+31+30+31+31+30+31+30;day=31;break;
第二次上机作业(2020)
1.求30以内的所有素数之和。
代码:
#include<stdio.h>
#define MAX 30
int main()
{
int n=1,i,j,k,s=0;
for(i=1;i<=30;i++)
{
k = 0;
for(j=2;j<i;j++)
{
if (i % j == 0)
{
k++;
case 6:h=31+28+31+30+31;day=30;break;
case 7:h=31+28+31+30+31+30;day=31;break;
case 8:h=31+28+31+30+31+30+31;day=31;break;
case 9:h=31+28+31+30+31+30+31+31;day=30;break;
{
printf(" * \n");
printf(" *** \n");
printf(" ***** \n");
printf("*******\n");
printf(" ***** \n");
printf(" *** \n");
printf(" * \n");
return 0;
}
结果:
代码:
#include <stdio.h>
int main()
{
int year,month,day;
scanf("%d%d%d",&year,&month,&day);
if((day==31)&&(month==12))
{
year += 1;
month = 1;
day = 1;
}
else if((day==31)&&(month!=12))
}
printf("%.4f",e);
return 0;
}
int JieCheng(int n)
{
int i;
double sum=1;
for(i=1;i<=n;i++)
sum=sum*i;
return sum;
}
结果:
3.计算机自动出0-9之间的四则运算(+ - * /)计算题;由用户输入结果,然后自动批改结果是否正确。(采用生成随机数方式确定)
return f;
}
int main()
{
float a,b,c,fa,fb,fc;
while(1)
{
printf("Please input the lower and upper boundaries:");
scanf("%f%f",&a,&b);
fa=function(a);
fb=function(b);
case 2:printf("");break;
case 3:printf("");break;
case 4:printf("");break;
case 5:printf("");break;
case 6:printf("");break;
default:break;
}
while(1)
{
if(i>day) break;
else printf("\nCorrect!\n");
return 0;
}
结果:
4.用二分法求方程2x3-4x2+3x-6=0在(a,b)之间的根。
例:输入Please input the lower and upper boundaries: 3 10
输出No root in this boundary!
Please input the lower and upper boundaries: 1 5
The root is 2.00
代码:
#include <stdio.h>
#include <math.h>
float function(float x)
{
float f;
f=2*x*x*x-4*x*x+3*x-6;
相关文档
最新文档