浙江大学2004-2005上学期“程序设计基础--C”试卷

合集下载

浙江大学C语言程序设计理论考试模拟试题答案

浙江大学C语言程序设计理论考试模拟试题答案

浙江大学C语言理论考试模拟试题答案一、判断题共10题,每题1分,共10分。

正确的请选择A,错误的请选择B。

1、在C语言中,函数不可以嵌套定义,但函数可以嵌套调用。

AA、正确B、错误解答:A2、在程序中else 子句可以单独使用。

BA、正确B、错误解答:B3、C 语言源程序文件通过了编译、连接之后, 生成一个后缀为.EXE 的文件。

( ) AA、正确B、错误解答:A4、_ya是不合法的C语言标识符。

BA、正确B、错误解答:B5、在数组初始化时,如果初值个数多于数组长度,将出现错误。

AA、正确B、错误解答:A6、C语言规定,函数返回值的类型是由return语句中的表达式类型所决定。

BA、正确B、错误解答:B7、若有定义int *p, 则表达式p++ 的值就是p 所指向的变量的地址值加1。

BA、正确B、错误解答:B8、'\n'不是一个字符常量。

BA、正确B、错误解答:B9、表达式(z=0, (x=2)||(z=1),z) 的值是1。

BA、正确B、错误解答:B10、若打开文件的方式为“w”而该文件已经存在,则文件中原有数据被清空。

A、正确B、错误二、单选题请从给定的选项中选择一个唯一正确的选项。

每小题2分,共10题,20分。

1、 C下面有关变量的命名,不合法的是:( )A. _intB. __intintC. __int&intD. ___intintintC解答:C2、有变量定义int a;float c;下面输入语句有语法错误的是( )。

A. scanf("%d,%f", &a, &c);B. scanf("x=%d, c=%f", &a, &c);C. scanf("%d%f", &a, &c);D. scanf("%f %d",&a, &c);D解答:D3、下面关于函数参数使用的说法,不正确的是:()A. 函数调用时实参按顺序传递到形参;B. 函数调用时实参把值传递给形参;C. 函数的实参和形参个数可以不一致,但使用时应尽量一致;D. 函数的实参和形参可以同名;C解答:C4、已知int k=1; for(k=1;1;k++) if(k) break; for语句的循环次数是( )。

C语言程序设计试题4

C语言程序设计试题4

浙江大学“程序设计基础-C”试题卷2001-2002学年春季学期考试时间: 2002年6月30日下午2:00-4:00注意:答题内容必须写在答题卷上,写在本试题卷上无效一.单项选择题(每题2分,共20分)1. 1. C 语言程序的三种基本结构是顺序结构、选择结构和______结构。

A.递归B.转移C.循环D.嵌套2. 2.下列运算符中,优先级最高的是_____。

A.-> B.++ C.&& D.=3. 3.表达式!(x>0&&y>0) 等价于_____。

A.!(x>0)||!(y>0) B.!x>0||!y>0 C.!x>0&&!y>0 D.!(x>0)&&!(y>0)4. 4.表达式sizeof("\nsum=%d\n") 的值是______。

A.8 B.9 C.10 D.115. 5.以下选项中不正确的实型常量是_____。

A.0.23E B.2.3e-1 C.1E3.2 D.2.3e06. 6.表达式______的值不是1。

A.0?0:1 B.5%4 C.!EOF D.!NULL7. 7.数组定义为int a[11][11],则数组a 有_____个数组元素。

A.12 B.144 C.100 D.1218. 8.对于以下的变量定义,表达式______是不正确的。

struct node {int j, k;} x, *p=&x;A.p->k=2 B.(*p).k=2 C.x.k=2 D.x->k=29. 9.不正确的赋值或赋初值的方式是______。

A.char str[ ]="string"; B.char str[10]; str="string";C.char *p="string"; D.char *p; p="string";10. 10.设程序中不再定义新的变量,写出在函数main中可以使用的所有变量______。

浙大_建筑构造00-05年真题整理版带答案解...

浙大_建筑构造00-05年真题整理版带答案解...

浙江大学建筑学建筑构造部分2000一名词解释:1勒脚及其作用:墙角是指室内地面以下,基础以上的这段墙体,外墙的墙角称勒角。

P192圈梁及其作用:圈梁是沿砌体房屋外墙四周及横墙设置的连续封闭的水平梁。

圈梁的作用是增加房屋的整体刚度和稳定性,减轻地基不均匀沉降对房屋的破坏,抵抗地震力的影响。

P233隔断及其作用:4刚性防水屋面及其优缺点:刚性防水屋面只指用细石混凝土作防水层的屋面,因混凝土属于脆性材料,抗拉强度教低,故叫刚性防水屋面。

主要优点是构造简单,施工方便,造价较低;缺点是易开裂,对气温变化和屋面基层的变形的适应较差。

P124二问答题1简述建筑构造设计的原则。

1.坚固实用2.技术先进3.经济合理4.美观大方三做一楼梯剖面图。

某中学教学楼层高为米,楼梯间宽度为米。

进深为米,室内外地坪高差为米。

试设计一双折式梯段的楼梯。

要求在梯段休息平台下做出入口,并保证平台梁第净高大于等与2100mm.2001图为某单元式错层住宅底层平面及其剖面示意图。

该住宅层高米,室内外高差为600。

采用砖混结构,墙厚240,楼板均为现浇钢筋混凝土板,底层地面结构层作法自定。

卧室地面采用木装修面层,阳台面层为防滑地砖,阳台栏杆采用漏空栏杆。

1请作出勒脚详图A-A,(自室外地面至窗台)2请作出阳台详图B-B,(自标高为中心,上下各取约1米)3请通过计算确定楼梯踏步尺寸(宽和高)和楼梯开间、进深的最经济尺寸,并作出楼梯间的标准层(二层)平面图1:50。

图中应注出必要的尺寸和平台标高。

2002图为某办公楼局部平面,剖面示意图。

该办公室采用砖混结构。

所有墙厚都为240。

楼面、屋面均采用现浇钢筋混凝土结构。

屋面找坡采用材料垫坡。

防水方式自定。

所有房间地面面层采用木装修,外廊面层及栏杆做法自定。

1请做(1)剖面详细图2请做(2)剖面详细图3请做(3)剖面详细图(范围:以标高为中心,上下各约米)注:以上所有详土中均应注明各部位材料做法及有关尺寸。

浙江大学“C程序设计及实验”试题卷

浙江大学“C程序设计及实验”试题卷

浙江大学“C程序设计及实验”试题卷2003-2004学年春季学期考试时间: 2004年6月25日上午8:30-10:30注意:答题内容必须写在答题卷上,写在本试题卷上无效一.单项选择题(每题1分,共10分)1. C 语言程序的三种基本结构是顺序结构、选择结构和__C____结构。

A.递归B.转移C.循环D.嵌套2. 下列运算符中,优先级最高的是__B___。

A.+= B.[ ] C.? : D.&3. 运算符___A__ 不能做为单目运算符。

A./ B.& C.* D.+4. 以下选项中不正确的字符常量是___C__。

A.'1' B.'\0' C.'%d' D.105. 表达式x&&1 等价于_C____。

A.x==0B.x==1C.x != 0D.x != 16. 已知字符‘a’ 的ASCII码为97 ,执行下列语句的输出是__A___。

printf ("%c%d", ’b’, ’b’+1 ) ;A.b99B.98c C.9899D.bc7. 在C 语言程序中,在函数内部定义的变量称为__C____。

A.全局变量B.外部变量C.局部变量D.内部变量8. 执行语句printf(" ___D___", "hello"); 将得到出错信息。

A.%u B.%s C.%x D.%f9. 对于以下的变量定义,表达式___D___是不正确的。

struct node {float x, y;} point, *p=&point;A.p->x=2.0 B.(*p).y=3.0 C.point.x=2.0 D.*p->y=3.010. 对于变量定义:int **p[10], p 是一个__B___。

A.指针B.数组C.函数D.数组元素二、填空题(每题2分,共30分)1. 写出计算s(s-a)(s-b)(s-c)的C语言表达式______。

浙江大学“程序设计基础-C”试题卷

浙江大学“程序设计基础-C”试题卷

浙江大学“程序设计基础-C”试题卷一.单项选择题(每题2分,共20分)1.C语言程序的三种基本结构是顺序结构、选择结构和______结构。

A.递归B.转移C.循环D.嵌套2.下列运算符中,优先级最高的是_____。

A.->B.++C.&&D.=3.表达式!(x>0&&y>0)等价于_____。

A.!(x>0)||!(y>0)B.!x>0||!y>0C.!x>0&&!y >0D.!(x>0)&&!(y>0)4.表达式sizeof("\nsum=%d\n")的值是______。

A.8B.9C.10D.115.以下选项中不正确的实型常量是_____。

A.0.23EB.2.3e-1C.1E3.2D.2.3e06.表达式______的值不是1。

A.0?0:1B.5%4C.!EOFD.!NULL7.数组定义为inta[11][11],则数组a有_____个数组元素。

A.12B.144C.100D.1218.对于以下的变量定义,表达式______是不正确的。

structnode{intj,k;}x,*p=&x;A.p->k=2B.(*p).k=2C.x.k=2D.x->k=2 9.不正确的赋值或赋初值的方式是______。

A.charstr[]="string";B.charstr[10];str="stri ng";C.char*p="string";D.char*p;p="string";10.设程序中不再定义新的变量,写出在函数main中可以使用的所有变量______。

#include<stdio.h>intz;intp(intx){staticinty;return(x+y);}voidmain(){inta,b;printf("%d\n",p(a));……}A.a,bB.a,b,zC.a,b,y,zD.a,b,x,y,z二、填空题(每题2分,共30分)1.设字符型变量ch的值是小写英文字母,将它转换为相应大写字母的表达式是______。

浙大C程序设计期末试卷-c_2004A

浙大C程序设计期末试卷-c_2004A

A.3
B.7
C.10
D.11
9. After running the following code fragment, the value of s is ______.
int i=5, s=0;
《C Programming》TEST PAPER, Jan 22, 2005
1/8
do if (i%2) continue; else s+=i; while (--i);
1. The precedence of operator _____ is the lowest one.
A.? :
B.==
C.+=
D.&
2. _____ is correct if it is used as a character constant.
A.’\’
B.'\080'
C.'%d'
D.0xa
1 4 7 10 13 16 19 22 25. 6. According to the declaration: int a[10], *p=&a[1]+2; the last element of array a is p[__]. 7. Write the declaration_____ with typedef, which makes PA a synonym for a character pointer
{
int x = 2; P(x*F(2));
}
{ for (; x < 10; x += 50)
P2(x, 9.15*x+32);
}
《C Programming》TEST PAPER, Jan 22, 2005

浙江大学“程序设计基础-C”试题卷 (2)

浙江大学“程序设计基础-C”试题卷 (2)

2000~2001学年“程序设计基础--C”试卷考试时间:2000年6月27日下午2:00-4:00注:请将答案写在答题卷上一、单项选择题(每题2分,共30分)1.______是合法的用户自定义标识符。

A、b-bB、floatC、<fr>D、_isw2.若变量已正确定义并赋值,表达式______不符合C语言语法。

A、a*b/c;B、3.14%2C、2,bD、a/b/c3._____是不正确的字符常量。

A、'\n'B、'1'C、"a"D、'\101'4.在C程序中,用_____表示逻辑值“真”。

A、1B、非0的数C、非1的数D、大于0的数5.______把x、y定义成float类型变量,并赋同一初值3.14。

A、floatx,y=3.14;B、floatx,y=2*3.14;C、floatx=3.14,y=x=3.14;D、floatx=y=3.14;6.若变量已正确定义,表达式______的值不是2。

A、2&3B、1<<1C、a==2D、1^37.若变量已正确定义,语句“if(a>b)k=0;elsek=1;”和______等价。

A、k=(a>b)?1:0;B、k=a>b;C、k=a<=b;D、a<=b?0:1;8.设变量定义为“inta,b;”,执行下列语句时,输入_____,则a和b的值都是10。

scanf("a=%d,b=%d",&a,&b);A、1010B、10,10C、a=10b=10D、a=10,b=109.下列程序的输出结果是_____。

fun(inta,intb,intc){c=a*b;}main(){intc;fun(2,3,c);printf(”%d\n”,c);}A、0B、1C、6D、无法确定10.在C程序中,若对函数类型未加说明,则函数的隐含类型为_____。

浙大C++2005~2006春浙江大学考试答答案和评分标准

浙大C++2005~2006春浙江大学考试答答案和评分标准

浙江大学2005–2006学年_春_季学期《面向对象程序设计》课程期末考试试卷开课学院:计算机学院,考试形式:闭卷考试时间:_2006_年_4_月_18_日,所需时间: 120 分钟,任课教师_________ 考生姓名: _____学号:专业: ________1. Write the output of the code below(20%):每题4分1)int aa1=53,aa2=69;void f(int a1,int &a2){a2=a1;a1+=a2;cout << aa1 << aa2 << endl; //看清楚题目aa2 -= 7;a2++;}void main(){f(aa1,aa2);cout << aa1 << aa2 <<endl;}535353472) class A{static int m; //careint n;public:A(int m,int n){this->m=m;this->n=n;}Print(){ cout << m <<"---" << n << endl;}};int A::m; //改错时候注意void main(){A a1(3,4);A a2(5,6);a1.Print();a2.Print();}5---45---63)char a['z'];for (char i='a';i<='z';i++)a[i] = 'A'+i-'a';cout << a['e'] << endl;for (char i='a';i<='z';i++)a[i] = '1'+i-'a';cout << a['e'] << endl;E54)#include <iostream>using namespace std;class A {int i;public:A():i(10) { cout << "A() " <<i <<"\t"; f(); }virtual ~A() { cout << "~A() " << "\t"; }virtual void f() { i+=11; cout << "A::f() " <<i <<"\t"; }void g() { i+=12; cout << "A::g() "<<i<<"\t"; }};class B : public A {int i;public:B():i(20) { cout << "B() " <<i <<"\t"; f();}~B() { cout << "~B() " << "\t"; }void f() { i+=22; cout << "B::f() " <<i <<"\t"; }void g() { i+=12; cout << "B::g() "<<i<<"\t"; }};B gen(){return B();}int main(){A* p = new B();p->f();cout <<endl;A a;B b = gen();a = b;a.f();cout <<endl;b.g();delete p;return 0;}A() 10 A::f() 21 B() 20 B::f() 42 B::f() 64A() 10 A::f() 21 A() 10 A::f() 21 B() 20 B::f() 42 A::f() 32 B::g() 54 ~B() ~A() ~B() ~A() ~A()此题答案不要求tab的对齐,但是如果存在换行错误(多余的或缺少的),所有的换行错误合计扣1分5)void main(){int m = 555;int n = 666;int &k = m;k++;cout << m <<”----“ << n << endl;k = n;k++;cout << m <<”----“ << n << endl;}556----666667----6662. Please choose the correct answer(15%)1-6每题2分,第7题3分D1、In C++ Language,function prototype doesn’t identify ( )A. The return type of the function.B. The number of arguments of the functionC. The type of arguments of the function.D. The functionality of the functionB 2、In C++ program, objects communicate each other by ( )A. InheritanceB. Calling member functionsC. EncapsulationD. Function overloadingB 3、For an arbitrary class,the number of destructor function can’t be bigger than ( )A. 0B. 1C. 2D. 3C 4、 Suppose a class is defined without any keywords such as public, private and protected,all members default to: ( )A. publicB. protectedC. privateD. staticC 5、About inline function, which statement is correct? ( )A. When the program is executed, inline function will insert the object code to every place where this function is called.B. When the program is compiled, inline function will insert the object code to every place where this function is called.C. Inline function must be defined inside a class.D. Inline function must be defined outside a class with keyword “inline”.B 6、During public inheritance, which statement is incorrect concerning the base class objects and the derived class objects? ( )A. Derived class objects can be assigned to base class objects.B. Derived class objects can initialize base class references.C. Derived class objects can access the members of base class.D. The addresses of derived class objects can be assigned to base class pointers.C 7、For the class definition:class A{public:virtual void func1( ){ }void func2( ){ }};class B: public A{public:void func1( ){cout<< ″ class B func 1 ″ <<end1;}virtual void func2( ){cout<< ″ class B func 2 ″ <<end1;}};Which statement is correct? ( )A. Both A::func2( ) and B::func1( ) are virtual functionsB. Both A::func2( ) and B::func1( ) are not virtual functionsC. B::func1( ) is virtual function, while A::func2( ) is not virtual functionD. B::func1( ) is not virtual function, while A::func2( ) is virtual function3. Please correct the following programs(point out the errors and correct them)(15%) 1) 6分,每错2分class A{protected:static int k;int m;public:};int A::k;class B : public A{int n;public:static void F(int k){this->A::k = k;}void F2(int m){this->m = m;}};void main(){B b1,b2;b1.F(3);b2.F2(5);}2)2分char a[3];const char *const ptr = a;const char c = 'a';ptr = &c;3) 2分class base{...public:virtual void f(void)=0;virtual void g(void)=0;}class derived: public base{...public:virtual void f(void);virtual void g(void);};derived d;4) 5分,前3错各1分,最后一题错2分(基本正确给一分),class A{int *m_ip;public:A(int *ip = NULL){if(ip){m_ip = new int[5];::memcpy(m_ip,ip,sizeof(int)*5);}elsem_ip = NULL;}~A(){delete m_ip; //改成 delete [] m_ip更好}A operator+(const A &a) const { // (1)(2)A temp(m_ip);for (int i=0; i<5; i++)temp.m_ip[i] += a.m_ip[i];return temp;}const A &operator=(const A &a){ // (3)if(a.m_ip){m_ip = new int[5];::memcpy(m_ip,a.m_ip,sizeof(int)*5);}elsem_ip = NULL;return *this;}friend ostream operator<<(ostream &,const A &);};ostream operator<<(ostream &out ,const A &a); // (4){out << “(“ ;for (int i=0;i<4;i++)out << a.m_ip[i] << “,”;return out << a.m_ip[5] << “)”;}// Suppose the following code is correctvoid main(){const int k[5]={3,5,6,2,1};const A a1(k),a2(k);A a3(k);a3 = a1+a2;cout << a3 << endl;}4、Fill in the blanks(30%)每格2分1)The function template MaxMin() can find out the max and min of a two dimension array,row is first dimension of length and col is second dimension of length . #include <iomanip.h>template <class T> void MaxMin(T* array,int row,int col){T max = array[0],min = array[0];for(_int i=0 ;i<row;i++)for( int j=0 ;j<col;j++){if( max <array[i*col+j] )max = array[i*row+j];if( min > array[i*col+j] )min = array[i*row+j];}cout << "max=" << max << endl;cout << "min=" << min << endl;}void main(){int ai[2][3]={{8,10,2},{14,4,6}};MaxMin( (int*)ai, 2, 3 );}2) Please fill in the suitable code to make the program results 60。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

浙江大学2004-2005学年冬季学期《C Programming》课程期末考试试卷开课学院:计算机学院, 考试形式:闭卷考试时间:2005年1月22日, 所需时间:120 分钟考生姓名: 学号: 专业:(注意:答题内容必须写在答题卷上,写在本试题卷上无效) Section 1: Single Choice(2 mark for each item, total 20 marks)1. The precedence of operator _____ is the lowest one.A.? : B.== C.+= D.&2. _____ is correct if it is used as a character constant.A.’\’ B.'\080' C.'%d' D.0xa3. According to the declaration: char c1=92,c2=92; the value of expression _____ is 0.A.c1^c2 B.c1&c2 C.~c2 D.c1|c24. According to the declaration: int x=11; the value of expression (x++*1/3) is_____.A.3B.4 C.0D.3.6675. The value of expression sizeof("\num=%d\t") is ______.A.7 B.8 C.9 D.106. In the following assignments or initialization, ______ is wrong.A.char s[ ]="hello"; B.char s[10]; s="hello";C.char *p="hello"; D.char *p; p="hello";7. The following code fragment prints out ______.#define MA(x, y) (x)*(y)int i = 2;i = 3/MA(i, i+2)+5;printf(“%d\n”, i);A.5 B.8 C.9 D.118. static struct {int x, y[3];} a[3] = {{1,2,3,4},{5,6,7,8},{9,10,11,12}}, *p;p = a+1;The value of expression *((int *)(p+1)+2) is ______.A.3 B.7 C.10 D.119. After running the following code fragment, the value of s is ______.int i=5, s=0;《C Programming》TEST PAPER, Jan 22, 2005 1 / 8do if (i%2) continue; else s+=i; while (--i);A.15 B.9 C.6 D.510. According to the declaration: int (*p)[10], p is a(n) ______.A.pointer B.array C.function D.element of arraySection 2: Fill in the blanks(2 mark for each item, total 30 marks)1. The value of expression 1+4/5+15<7+4%5+(8,10) is ______.2. The value of expression !!10 is _____.3. The value of expression 3>2>1 is _____.4. The value of expression ~(-1<<1) is ______.5. The statement for (i=1; i<=9; i++) printf(“%3d”, ______);prints out the following numbers:1 4 7 10 13 16 19 22 25.6. According to the declaration: int a[10], *p=&a[1]+2; the last element of array a is p[__].7. Write the declaration_____ with typedef, which makes PA a synonym for a character pointerarray, which contains 100 elements.8. The following code fragment prints out _____.static int a[3][4]={{1,2,3},{4,5,6}};printf(“%d”,a[0][5]);9. The following code fragment prints out _____.char a[]={“678”,”45”},**p=a+1;printf(“%s,%c”,*p,**p-1);10. The following code fragment prints out _____.int *p, *q, k = 1, j=10 ;p=&j; q = &k ; p = q ; (*p)++;printf("%d",k);11. The following program prints out _____.#include <stdio.h>void f(int *x,int *y){ int *p;p=x; x=y; y=p;}void main(){ int x=1, y=2;f(&y, &x);printf("%d, %d", x, y);}12. The following program prints out _____.#include <stdio.h>#include <string.h>main(){ char st[20]=”hello\0world!”;《C Programming》TEST PAPER, Jan 22, 2005 2 / 8printf(“%d,%d\n”,strlen(st),sizeof(st));}13. To execute the command: prog 123 456 ABC, the value of *(++argv[2]) is_____.14. The following program fragment prints out _____.i;intint f(int x){ static int k = 0;x+=k++;x;return}i=f(2);i=f(3);printf(“%d”,i);15. The following program fragment prints out _____.int f(int x){ return ((x>0)? x*f(x-1):3); }printf(“%d”,f(f(1)));Section 3: Read each of the following programs and answer questions (5marks for each item, total marks: 30)1.The output of the following program is _______.#include <stdio.h>void main(){int i,j,k=19;while (i=k-1) {k-=3;if(k%5==0) { i++; continue; }else if(k<5) break;i++;}printf(“i=%d,k=%d\n”,i,k);}2.When input: AabD <ENTER>, The output of the following program is _______.#include <stdio.h>void main(){char s[81];int i=0;gets(s);《C Programming》TEST PAPER, Jan 22, 2005 3 / 8while (s[i]!=‘\0’){if(s[i]<= ’z’&&s[i]>= ’a’)s[i]= ’z’+’a’-s[i];i++;}puts(s);}3.The output of the following program is _______.#include <stdio.h>x,y,z,w;intvoid p(int x, int *y)z;{ int++x;++*y;z=x+*y;w+=x;x,*y,z,w);printf(“%2d%2d%2d%2d#”,}main()void{ x=y=z=w=2;p(y, &x);x,y,z,w);printf(“%2d%2d%2d%2d\n”,}4.The output of the following program is _______.#include <stdio.h>#define F(k) k+3.14#define P(a) printf("a=%d\n", (int)(a))#define P1(a) P(a);putchar('\n');#define P2(a, b) P(a);P1(b);void main(){int x = 1;{int x = 2;P(x*F(2));}{for (; x < 10; x += 50)P2(x, 9.15*x+32);}《C Programming》TEST PAPER, Jan 22, 2005 4 / 8}5.When input: this is a test.<ENTER>, The output of the following program is _______.#include <stdio.h>#define TRUE 1#define FALSE 0int change(char *c,int status);void main(){int flag=TRUE;ch;chardo{ch=getchar();flag=change(&ch,flag);putchar(ch);} while(ch!=’.’);printf(“\n”);}int change(char *c,int status){if(*c==’ ‘) return TRUE;if(status&&*c<=’z’&&*c>=’a’) *c+=’A’-‘a’;return FALSE;}6.There are three text files f1,f2 & f3, each of them contains some characters as following: file name contentsaaa!f1f2 bbb!f3 ccc!Compiling the following C source codes, and linking the related object codes, an executable command file ex12.exe will be produced. To execute the command at DOS prompt: ex12 f1 f2 f3<ENTER>,the output is: .#include <stdio.h>main(int argc, char *argv[]){FILE *fp;*);voidsub(FILEint i=1;(--argc>0)whileif ((fp=fopen(argv[i++],“r”))==NULL) {printf(“Cannot open file!\n”);《C Programming》TEST PAPER, Jan 22, 2005 5 / 8《C Programming 》TEST PAPER, Jan 22, 2005 6 / 8 exit(1);} else {sub(fp);fclose(fp);}}void sub(FILE *fp){char c;while((c=getc(fp))!=‘!’) putchar(c+1);}Section 4: According to the specification, complete each program (2 mark for each blank, total: 20 marks)1.The following program is to calculate the value of “e ” according to the formulaΛ++++=!31!21!111e , while the value of the last item must be less than 10- 6. #include <stdio.h>main(){int i;double e,item;(1) ;item=1.0;for (i=1; (2) ;i++) {item/=(double)i;e+= (3) ;}printf(“e=%f\n”,e);}2.The following program deletes the non-nested comments which be included between /* and */from the C source program file exam.c , and stores the results in the file exam.out .#include <stdio.h>void delcomm(FILE *fp1,FILE *fp2){int c,i=0;while(( (4) )!=EOF)if (c==‘\n’)fprintf(fp2,“\n”);elseswitch(i){case 0:i=1;if(c==‘/’)fprintf(fp2,“%c”,c);elsebreak;1:casei=2;if(c==‘*’)else {fprintf(fp2,“/%c”,c);i=0;}break;2:casei=3;if(c==‘*’)break;case3:i=(c==‘/’)? (5);break;}}void main(){FILE *fp1,*fp2;fp1=fopen(“exam.c”,“r”);fp2=fopen(“exam.out”,“w”);delcomm( (6));(7);return;}3.Given: the pointer head points to the first node of the simple list. The following function del() deletes the first node which value is equal to num from the simple list.#include <stdio.h>struct student {int info;student*link;struct};struct student *del(struct student *head,int num){struct student *p1,*p2;if(head==NULL)《C Programming》TEST PAPER, Jan 22, 2005 7 / 8printf(“\nlistnull!\n”);else {p1=head;(8)) {while(p2=p1;p1=p1->link;}if(num==p1->info){(9);if(p1==head)else (10);printf(“delete:%d\n”,num);else}printf(“%d not been found!\n”,num);}return(head);}《C Programming》TEST PAPER, Jan 22, 2005 8 / 8。

相关文档
最新文档