2013年上半年程序員考試下午真題

程序員 責(zé)任編輯:YLM 2017-08-17

添加老師微信

備考咨詢

加我微信

摘要:以下是由希賽網(wǎng)整理的2013年上半年程序員考試下午真題,希望對備考程序員考試的考生有所幫助。

2013年上半年程序員考試下午真題:

>>>點擊進(jìn)入軟考初級程序員歷年真題下載

● 閱讀以下說明和流程圖,填補流程圖中的空缺(1)~ (5) ,將解答填入答題紙的對應(yīng)欄內(nèi)。
【說明】
平面上一個封閉區(qū)域內(nèi)穩(wěn)定的溫度函數(shù)是一個調(diào)和函數(shù)。如果區(qū)域邊界上各點的溫度是己知的(非常數(shù)),那么就可以用數(shù)值方法近似地計算出區(qū)域內(nèi)各點的溫度。
假設(shè)封閉區(qū)域是矩形,可將整個矩形用許多橫豎線切分成比較細(xì)小的網(wǎng)格,并以最簡單的方式建立坐標(biāo)系統(tǒng),從而可以將問題描述為:己知調(diào)和函數(shù)u(i,j)在矩形 {0≤i≤m; 0≤j≤n}四邊上的值,求函數(shù)u在矩形內(nèi)部各個網(wǎng)格{(i,j)|i=1,....m-1; j=1,.....,n-1}上的近似值。
根據(jù)調(diào)和函數(shù)的特點可以推導(dǎo)出近似算式:該矩形內(nèi)任一網(wǎng)格點上的函數(shù)值等于其上下左右四個相鄰網(wǎng)格點上函數(shù)值的算術(shù)平均值。這樣,我們就可以用法代法來進(jìn)行數(shù)值計算了。首先將該矩形內(nèi)部所有網(wǎng)格點上的函數(shù)值設(shè)置為一個常數(shù),例如 u(0,0); 然后通過該法代式計算矩形內(nèi)各網(wǎng)格點上的新值。這樣反復(fù)進(jìn)行法代計算,若某次迭代后所 有的新值與原值之差別都小于預(yù)定的要求(如0.01),則結(jié)束求解過程。
【流程圖】
1.png

● 閱讀以下說明和C函數(shù),填充函數(shù)中的空缺,將解答填入答題紙的對應(yīng)欄內(nèi)。
【說明】
函數(shù)GetDateld(DATE date)的功能是計算并返回指定合法日期date是其所在年份的第幾天。例如,date表示2008年1月25日時,函數(shù)的返回值為25,date表示2008年3月3日時,函數(shù)返回值為63。
函數(shù)Kday_Date(int theyear,int k)的功能是計算并返回指定合法年份theyear(theyear≥1900)的第k天(1≤k≤365)所對應(yīng)的日期。例如,2008年的第60天是2008年2月29日,2009 年的第60天是2009年3月1日。
函數(shù)isLeapYear(int y)的功能是判斷y代表的年份是否為閏年,是則返回1,否則返回0。
DATE 類型定義如下:
typedef struct {
int year ,month ,day;
}DATE;
【C函數(shù)1】
int GetDateld( DATE date )
{
const int days _month[13] = { 0,31,28,31,30,31,30,31,31,30,
31,30 ,31 );
int i ,date_id = date.day;
for ( i = 0; i < (1) ; i++ )
date_id += days_month[i];
if ( (2) && isLeapYear(date.year) ) date_id++;
return date_id;
}
【C函數(shù)2】
(3) Kday_Date(int theyear ,int k)
{
int i;
DATE date;
int days_month(13) = { 0,31,28,31,30,31,30,31,31,30,31,30,31};
assert(k>=l && k<=365 && theyear>=1900); /*不滿足斷言時程序終止*/
date .year = (4) ;
if (isLeapYear(date.year)) days_month[2]++;
for (i=1; ; ) {
k = k - days_month(i++);
if (k<=0) { date .day = k + (5) ; date.month = i-1; break; }
}
return date;
}

● 閱讀以下說明和C程序,填充程序中的空缺,將解答填入答題紙的對應(yīng)欄內(nèi)。
【說明】
埃拉托斯特尼篩法求不超過自然數(shù)N的所有素數(shù)的做法是:先把N個自然數(shù)按次序排列起來,1不是素數(shù),也不是合數(shù),要劃去; 2是素數(shù),取出2(輸出),然后將2的倍數(shù)都劃去:剩下的數(shù)中最小者為3,3 是素數(shù),取出3(輸出),再把3的倍數(shù)都劃去;剩下的數(shù)中最小者為5,5是素數(shù),再把5的倍數(shù)都劃去。這樣一直做下去,就會把不超過N的全部合數(shù)都篩掉,每次從序列中取出的最小數(shù)所構(gòu)成的序列就是不超過N的全部質(zhì)數(shù)。
下面的程序?qū)崿F(xiàn)埃拉托斯特尼篩法求素數(shù),其中,數(shù)組元素sieve[i](i>0)的下標(biāo)i對應(yīng)自然數(shù)i,sieve[i]的值為1/0分別表示i在/不在序列中,也就是將i劃去(去掉)時,就將sieve[i]設(shè)置為0。
【C 程序】
*include <stdio.h>
*define N 10000
int main __(3)__
{
char sieve[N+1] = {0};
int i = 0,k;
/*初始時2~N都放入sieve數(shù)組*/
for(i=2; (1) ; i++)
sieve[i] = 1;
for( k = 2; ;){
/*找出剩下的數(shù)中最小者并用k表示*/
for( ; k<N+1&& sieve[k]==0; (2));
if ( (3) ) break;
printf("%d\t",k); /*輸出素數(shù)*/
/*從sieve中去掉k及其倍數(shù)*/
for( i=k; i<N+1; i= (4) )
(5);
}/*end of for*/
return 0;
} /*end of main*/

● 閱讀以下說明和C程序,填充函數(shù)中的空缺,將解答填入答題紙的對應(yīng)欄內(nèi)。
【說明】
N個游戲者圍成一圈,從l~N順序編號,游戲方式如下:從第一個人開始報數(shù)(從1到3報數(shù)),凡報到3的人退出圈子,直到剩余一個游戲者為止,該游戲者即為獲勝者。
下面的函數(shù)playing(LinkList head)模擬上述游戲過程并返回獲勝者的編號。其中,N個人圍成的圈用一個包含N個結(jié)點的單循環(huán)鏈表來表示,如圖4-1所示,游戲者的編號放在結(jié)點的數(shù)據(jù)域中。
2.png在函數(shù)中,以刪除結(jié)點來模擬游戲者退出圈子的處理。整型變量c(初值為1)用于計數(shù),指針變量p的初始值為head(如圖4-1所示)。游戲時,從p所指向的結(jié)點開始計數(shù),p沿鏈表中的指針方向遍歷結(jié)點,c的值隨p的移動相應(yīng)地遞增。當(dāng)c計數(shù)到2時,就刪除p所指結(jié)點的下一個結(jié)點(因下一個結(jié)點就表示報數(shù)到3的游戲者),如圖4-2所示,然后將c設(shè)置為0后繼續(xù)游戲過程。
3.png結(jié)點類型定義如下:
typedef struct node{
int code; /*游戲者的編號*/
struct node *next;
}NODE,*LinkList;
【C 函數(shù)】
int playing(LinkList head ,int n)
{ /* head 指向含有n個結(jié)點的循環(huán)單鏈表的第一個結(jié)點(即編號為1的游戲者) */
LinkList p = head ,q;
int theWinner ,c = 1;

whi1e ( n > (1) ){
if (c == 2) { /*當(dāng)c等于2時,p所指向結(jié)點的后繼即為將被刪除的結(jié)點*/
q = p->next;
p->next = (2) ;
printf("%d\t" ,q->code); /*輸出退出圈子的游戲者編號時*/
free (q) ;
c = (3) ;
n--;
} /*if*/
p = (4) ;
c++;
}/*while*/
theWinner= (5) ;
free(p);
return theWinner; /*返回最后一個游戲者(即獲勝者)的編號*/
}

● 閱讀以下說明和Java程序,填充代碼中的空缺,將解答填入答題紙的對應(yīng)欄內(nèi)。
【說明】
某學(xué)校在學(xué)生畢業(yè)時要對其成績進(jìn)行綜合評定,學(xué)生的綜合成績(GPA)由其課程加權(quán)平均成績(Wg)與附加分(Ag)構(gòu)成,即GPA= Wg +Ag。
設(shè)一個學(xué)生共修了n門課程,則其加權(quán)平均成績 (Wg) 定義如下:
4.png其中 ,gradei 、Ci 分別表示該學(xué)生第 i 門課程的百分制成績及學(xué)分。
學(xué)生可以通過參加社會活動或?qū)W科競賽獲得附加分(Ag)。學(xué)生參加社會活動所得的活動分(Apoints)是直接給出的,而競賽分(Awards)則由下式計算(一個學(xué)生最多可參加m項學(xué)科競賽):
5.png
其中 ,li Si 分別表示學(xué)生所參加學(xué)科競賽的級別和成績。
對于社會活動和學(xué)科競賽都不參加的學(xué)生,其附加分按活動分為0計算。
下面的程序?qū)崿F(xiàn)計算學(xué)生綜合成績的功能,每個學(xué)生的基本信息由抽象類Student描述,包括學(xué)號(stuNo)、姓名(name) 、課程成績學(xué)分(grades) 和綜合成績 (GPA)等,參加社會活動的學(xué)生由類ActStudent描述,其活動分由Apoints表示,參加學(xué)科競賽的學(xué)生由類CmpStudent描述,其各項競賽的成績信息由awards表示。
【 C++代碼】
#include <string>
#include <iostream>
using namespace std;
const int N=5; /*課程數(shù)*/
const int M=2; /*競賽項目數(shù)*/

class Student{
protected:
int stuNo; string name;
double GPA; /*綜合成績*/
int (*grades) [2]; /*各門課程成績和學(xué)分*/
public:
Student ( const int stuNo ,const string &name ,int grades[ ] [2] ){
this->stuNo = stuNo; grades; this->name = name; this->grades =
grades;
}
virtual ~Student( ) { }
int getStuNo( ) {/*實現(xiàn)略*/
string getName( ) {/*實現(xiàn)略*/ }
(1) ;
double computeWg ( ){
int totalGrades = 0 ,totalCredits = 0;
for (int i = 0; i < N; i++) {
totalGrades += grades [i] [0] * grades [i] [1]; totalCredits +=
grades [i] [1];
}
return GPA =(double)totalGrades / totalCredits;
}
};
class ActStudent : public Student {
int Apoints;
public:
ActStudent(const int stuNo ,const string &name ,int gs[ ] [2] ,int
Apoints)
: (2) {
this->Apoints = Apoints ;
}
double getGPA ( ) { return GPA = (3) ;}
};
class CmpStudent: public Student{
private:
int (*awards) [2];
public:
CmpStudent (const int stuNo ,const string &name ,int gs[] [2] ,int
awards [ ] [2])
: (4) {this->awards = awards;}
double getGPA( ) {
int Awards = 0;
for (int i = 0; i < M; i++) {
Awards += awards [i] [0] * awards [i] [1];
}
return GPA = (5) ;
}
}
int main ( )
{ //以計算 3 個學(xué)生的綜合成績?yōu)槔M(jìn)行測試
int g1[ ] [2] = {{80 ,3} ,{90 ,2} ,{95 ,3} ,{85 ,4} ,{86 ,3}} ,
g2[ ][2] = {{60 ,3} ,{60 ,2} ,{60 ,3} ,{60,4} ,{65,3}} ,
g3[ ] [2] = {{80,3} ,{90,2} ,(70 ,3} ,{65,4} ,{75,3}}; //課程成績
int c3[ ] [2] = {{2 ,3} ,{3,3}}; //競賽成績
Student* students[3] = {
new ActStudent (101,"John" ,g1,3) , //3 為活動分
new ActStudent (102 ,"Zhang" ,g2 ,0),
new CmpStudent (103 ,"Li" ,g3 ,c3) ,
};
//輸出每個學(xué)生的綜合成績
for(int i=0; i<3; i++)
cout<< (6) <<endl;
delete *students;
return 0;

● 閱讀以下說明和Java程序,填充代碼中的空缺,將解答填入答題紙的對應(yīng)欄內(nèi)。
【說明】
某學(xué)校在學(xué)生畢業(yè)時要對其成績進(jìn)行綜合評定,學(xué)生的綜合成績(GPA)由其課程加權(quán)平均成績(Wg)與附加分(Ag)構(gòu)成,即GPA= Wg +Ag
設(shè)一個學(xué)生共修了n門課程,則其加權(quán)平均成績 (Wg) 定義如下:
6.png其中 ,gradei 、Ci 分別表示該學(xué)生第 i 門課程的百分制成績及學(xué)分。
學(xué)生可以通過參加社會活動或?qū)W科競賽獲得附加分(Ag)。學(xué)生參加社會活動所得的活動分(Apoints)是直接給出的,而競賽分(Awards)則由下式計算(一個學(xué)生最多可參加m項學(xué)科競賽):
7.png其中 ,li Si 分別表示學(xué)生所參加學(xué)科競賽的級別和成績。
對于社會活動和學(xué)科競賽都不參加的學(xué)生,其附加分按活動分為0計算。
下面的程序?qū)崿F(xiàn)計算學(xué)生綜合成績的功能,每個學(xué)生的基本信息由抽象類Student描述,包括學(xué)號(stuNo)、姓名(name) 、課程成績學(xué)分(grades) 和綜合成績 (GPA)等,參加社會活動的學(xué)生由類ActStudent描述,其活動分由Apoints表示,參加學(xué)科競賽的學(xué)生由類CmpStudent描述,其各項競賽的成績信息由awards表示。
【Java 代碼】
abstract class Student {
protected String name;
protected int stuNo;
protected double GPA; /*綜合成績*/
protected int [ ] [ ] grades; /*各門課程成績和學(xué)分*/
//其他信息略
public Student ( int stuNo ,String name ,int[ ] [ ] grades) {
this. stuNo = stuNo; grades; this.name = name; this.grades =
grades;
}
(1) ;
double computeWg( ){
int totalGrades = 0 ,totalCredits = 0;
for (int i = 0; i < grades.length; i++) {
totalGrades += grades [i] [0] * grades [i] [1] ;
totalCredits += grades [i] [1];
}
return (double)totalGrades / totalCredits;
}
}
class ActStudent extends Student {
private int Apoints;
ActStudent (int stuNo ,String name ,int[] [] grades ,int Apoints){
(2) ;
this. Apoints = Apoints;
}
public double getGPA( ) { return GPA = (3) ;
}
}
class CmpStudent extends Student {
private int [ ] [ ] Awards;
CmpStudent (int stuNo ,String name ,int[ ] [ ] grades ,int[ ] [ ] awards) {
(4) ;
this.Awards = awards;
}
public double getGPA__(6)__ {
int totalAwards = 0;
for (int i = 0; i < awards.length; i++) {
totalAwards += awards[i] [0] * awards[i] [1];
}
return GPA = (5) ;
}
}
public class GPASystem ( //以計算 3 個學(xué)生的綜合成績?yōu)榈惯M(jìn)行測試
public static void main(String[] args) {
int [ ] [ ] gl = {{80,3} ,{90,2} ,{95,3} ,{85,4} ,(86 ,3}) ,
g2 = {{60,3} ,{60,2} ,{60,3} ,{60,4} ,(65 ,3}) ,
g3 = {{80,3} ,{90,2} ,{70,3} ,{65,4} ,(75 ,3}); //課程成績
int [ ][ ] e1 = ((2 ,3) ,{1,2}} ,e2 = {{1,3}}; //競賽成績
Student students[ ] = {
new ActStudent (101,"John" ,gl ,3), / /3 為活動分
new ActStudent (102 ,"Zhang" ,g2 ,0) ,
new CmpStudent (103,"Li",g3,e2)};
}
//輸出每個學(xué)生的綜合成績
for (int i = 0; i < students .length; i++) (
System.out,println( (6) );
}
}
}

更多資料
更多課程
更多真題
溫馨提示:因考試政策、內(nèi)容不斷變化與調(diào)整,本網(wǎng)站提供的以上信息僅供參考,如有異議,請考生以權(quán)威部門公布的內(nèi)容為準(zhǔn)!

軟考備考資料免費領(lǐng)取

去領(lǐng)取

!
咨詢在線老師!