




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
千里之行,始于足下讓知識帶有溫度。第第2頁/共2頁精品文檔推薦操作系統(tǒng)課程設(shè)計(jì)報(bào)告模板中國石油高校(華東)操作系統(tǒng)課程設(shè)計(jì)報(bào)告
姓名:
學(xué)號:
成果:
名目
試驗(yàn)一、螺旋矩陣(3)
試驗(yàn)二、用Shell程序?qū)崿F(xiàn)文件的批量管理(4)
試驗(yàn)三、驅(qū)動下的螺旋矩陣程序(7)
試驗(yàn)四、哲學(xué)家進(jìn)餐問題(10)
試驗(yàn)五、NCURSE程序框架(14)
試驗(yàn)一、螺旋矩陣
一、試驗(yàn)任務(wù)
用C語言編寫一個螺旋矩陣程序,實(shí)現(xiàn)輸入行數(shù)和列數(shù)即可形成A~Z的螺旋矩陣,并用Makefile完成編譯。
二、試驗(yàn)環(huán)境和工具
VMwareWorkstation紅帽子Linux-2.4.20-8
三、關(guān)鍵代碼
1、螺旋矩陣實(shí)現(xiàn)代碼(SpiralMatrix.c)
#include
#defineN10
intmain()
{
introw,col,i,j,x,y,startNum;
intdx[4]={0,1,0,-1};//方向
intdy[4]={1,0,-1,0};
intMatrix[N][N];
printf("請輸入行數(shù)和列數(shù):");
scanf("%d%d",
for(i=0;i=0
else{
x-=dx[j];
y-=dy[j];
j=(j+1)%4;
}
x+=dx[j];
y+=dy[j];}
printf("螺旋矩陣為:\n");
for(i=0;iL)
min=L;
elsemin=H;
for(round=0;round97)count=count-33;
y=L-round-1;
for(x=round+1;x=round;y--)
{
a[x][y]=count;
count++;
if(count==91)
count=count-26;
}
y=round;
for(x=H-round-1-1;x>round;x--)
{
a[x][y]=count;
count++;
if(count==91)
count=count-26;
}
}
if(min%2==1)
{
if(H==L)a[H/2][H/2]=count;
elseif(H
#include
#include
#definePHILO_NUM5
#defineTHINK_TIME3
#defineEATING_TIME2
enum{THINKING,HUNGRY,EATING}state[PHILO_NUM];
pthread_cond_tself[PHILO_NUM];
intnoodles_num=68;
pthread_mutex_tlock;
voidtest(inti);
voidpickup(inti){
if(noodles_num!=0){
pthread_mutex_lock(
state[i]=HUNGRY;
test(i);
if(state[i]!=EATING)
pthread_cond_wait(
pthread_mutex_unlock(
}
else{
printf("Thenoodlesisempty!\n");
exit(0);}
}
voidputdown(inti){
pthread_mutex_lock(
state[i]=THINKING;
test((i+PHILO_NUM-1)%PHILO_NUM);
test((i+1)%PHILO_NUM);
pthread_mutex_unlock(
}
voidtest(inti){
if(state[(i+PHILO_NUM-1)%PHILO_NUM]!=EATING
pthread_cond_signal(
}
}
voidinit(){
inti=0;
for(;i
#include
#defineStartX20
#defineStartY6
voidinitial();
main(){
intx=StartX,y=StartY,ch;
initial();
box(stdscr,0,0);
attron(A_REVERSE);
mvaddstr(2,20,"NcurseTest");
attroff(A_REVERSE);
mvaddstr(6,19,"[*]jingcha");
mvaddstr(8,19,"[*]addusers");
mvaddstr(10,19,"[*]del");
mvaddstr(12,19,"[*]driversnake");
mvaddstr(14,19,"[*]Exit");
move(y,x);
do{
ch=getch();
switch(ch){
caseKEY_UP:if(y>=7)y=y-2;elsey=y;
break;
caseKEY_DOWN:if(y=6
elseif(y==14)y=6;
break;
case27:endwin();
exit(1);
default:
break;
}
move(y,x);
}while(1);
}
Programmer(){
intx=StartX,y=StartY,ch;
initial();
box(stdscr,0,0);
attron(A_REVERSE);
mvaddstr(2,20,"Programmer");
attroff(A_REVERSE);
mvaddstr(6,19,"[*]Compile");
mvaddstr(8,19,"");mvaddstr(10,19,"[*]Run");
mvaddstr(12,19,"");mvaddstr(14,19,"[*]CodeSourse");
mvaddstr(16,19,"");mvaddstr(18,19,"[*]Evaluate");
mvaddstr(20,19,"");mvaddstr(22,19,"[*]Exit");
move(y,x);
do{
ch=getch();
switch(ch){
caseKEY_UP:if(y==22)y=18;
elseif(y==18)y=14;
elseif(y==14)y=10;
elseif(y==10)y=6;
elsey=y;
break;
caseKEY_DOWN:if(y==6)y=10;
elseif(y==10)y=14;
elseif(y==14)y=18;
elseif(y==18)y=22;
elsey=y;
break;
case'\r':
if(y==22){endwin();clear();main();}
if(y==6){endwin();clear();Compile();}if(y==10){endwin();clear();Run();}
if(y==14){endwin();clear();Read();}
if(y==18){endwin();clear();Evaluate();}break;
case'\t':
if(y==6)y=10;
elseif(y==10)y=14;
elseif(y==14)y=18;
elseif(y==18)y=22;
elseif(y==22)y=6;
break;
case27:endwin();clear();main();
default:
break;
}
move(y,x);
}while(1);
}
policeman()
{
system("./demo5");
endwin();clear();main();
}
addusers(){
system("./add");
endwin();clear();main();
}
driver()
{
system("./test_demo");
endwin();clear();main();
}
del()
{
system("./del");
endwin();clear();main();
}
Compile(){
system("gcc-otest1test1.c-lncurses");
endwin();clear();Programmer();
}
Run(){
system("./test1");
endwin();clear();Programmer();
}
Read(){
system("gedittest1.c");
endwin();clear();Programmer();
}
Evaluate(){
intx=32,y=6,ch,n=0,m=0;
charname[15],words[80];
initial();
box(stdscr,0,0);
attron(A_REVERSE);
mvaddstr(2,20,"Evaluate");
attroff(A_REVERSE);
mvaddstr(6,19,"Username:");
mvaddstr(8,19,"Words:");
mvaddstr(14,19,"");mvaddstr(16,19,"[Apply]");
mvaddstr(18,19,"[Cancel]");
move(y,x);
do{
ch=getch();
switch(ch){
caseKEY_LEFT:if(x>=33elsex=x;
break;
caseKEY_RIGHT:if(x=33)mvaddch(y,--x,'');
break;
default:
if(y==6){
if(x>=32addch(ch);x++;n++;}}
if(y==8){
if(x>=32addch(ch);x++;m++;}else{y=10;x=32;}
}
if(y==10){
if(x>=32x++;m++;}
else{y=12;x=32;}
}
break;
}
move(y,x);
}while(1);
}
voidinitial(){
initscr();
cbreak();
nonl();
noecho();
intrflush(stdscr,FALSE);
keypad(stdscr,TRUE);
refresh();
}
2.ncurse代碼:
#include
#include
#defineStartX20
#defineStartY6
voidinitial();
main(){
intx=StartX,y=StartY,ch;
initial();
box(stdscr,0,0);
attron(A_REVERSE);
mvaddstr(0,20,"TCSNASServerv1.13byCyberAct");
attroff(A_REVERSE);
mvaddstr(6,19,"[*]ConfigIPaddressandnetmask");mvaddstr(8,19,"[*]ChangeAdministrator'sPassword");mvaddstr(10,19,"[*]Configusers>");
mvaddstr(12,19,"[*]Publishusersinnetwork");
mvaddstr(14,19,"[*]RestarttheServer");
mvaddstr(16,19,"[*]ShutdowntheServer");
mvaddstr(18,19,"[*]Exit");
move(y,x);
do{
ch=getch();
switch(ch){
caseKEY_UP:if(y>=7)y=y-2;elsey=y;
break;
caseKEY_DOWN:if(y=6
elseif(y==18)y=6;
break;
case27:endwin();
exit(1);
default:
break;
}
move(y,x);
}while(1);
}
ConfigIP(){
intx=32,y=6,ch;
charipstr[16],maskstr[16];
FILE*fp;
fp=fopen(".ip","rb");
fscanf(fp,"%s",ipstr);
fscanf(fp,"%s",maskstr);
fclose(fp);
initial();
box(stdscr,0,0);
attron(A_REVERSE);
mvaddstr(0,20,"ConfigIPaddressandnetmask");
attroff(A_REVERSE);
mvaddstr(6,19,"IPAddress:");
mvaddstr(6,32,ipstr);
mvaddstr(8,19,"Netmask:");
mvaddstr(8,32,maskstr);
mvaddstr(10,19,"");mvaddstr(12,19,"[Apply]");
mvaddstr(14,19,"[Cancel]");
move(y,x);
do{
ch=getch();
switch(ch){
caseKEY_LEFT:if(x>=33elsex=x;
break;
caseKEY_RIGHT:if(x=33)mvaddch(y,--x,'');
break;
case27:endwin();clear();main();
break;
default:
if(x>=32x++;}
break;
}
move(y,x);
}while(1);
}
ConfigUser(){
intx=StartX,y=StartY,ch;
initial();
box(stdscr,0,0);
attron(A_REVERSE);
mvaddstr(0,20,"Add/RemoveUser(s)");
attroff(A_REVERSE);
mvaddstr(6,19,"[*]UserList");
mvaddstr(8,19,"");
mvaddstr(10,19,"[*]AddaUnixUser");
mvaddstr(12,19,"[*]RemoveaUnixUser");
mvaddstr(14,19,"");mvaddstr(16,19,"[*]AddaWindowsUser");
mvaddstr(18,19,"[]RemoveaWindowsUser");
mvaddstr(20,19,"");mvaddstr(22,19,"[*]Exit");
move(y,x);
do{
ch=getch();
switch(ch){
caseKEY_UP:if(y==22)y=18;
elseif(y==18)y=16;
elseif(y==16)y=12;
elseif(y==12)y=10;
elseif(y==10)y=6;
elsey=y;
break;
caseKEY_DOWN:if(y==6)y=10;
elseif(y==10)y=12;
elseif(y==12)y=16;
elseif(y==16)y=18;
elseif(y==18)y=22;
elsey=y;
break;
case'\r':
if(y==22){endwin();clear();main();}
if(y==6){endwin();clear();UserList();}
if(y==10){endwin();clear();AddUnixUser();}
if(y==12){endwin();clear();RemoveUnixUser();}
if(y==16){endwin();clear();AddWindowsUser();}
break;
case'\t':
if(y==6)y=10;
elseif(y==10)y=12;
elseif(y==12)y=16;
elseif(y==16)y=18;
elseif(y==18)y=22;
elseif(y==22)y=6;
break;
case27:endwin();clear();main();
default:
break;
}
move(y,x);
}while(1);
}
UserList(){
intx=20,y=6,ch;
charname[20]="",ip[20]="";
FILE*fpu,*fpw;
initial();
box(stdscr,0,0);
attron(A_REVERSE);
mvaddstr(0,20,"UsersList");
attroff(A_REVERSE);
mvaddstr(y,x,"UnixUsers");
fpu=fopen(".Uuserlist","r");
while(!feof(fpu)){
y=y+2;
fscanf(fpu,"%s",name);
fscanf(fpu,"%s",ip);
if(!feof(fpu)){mvaddstr(y,x,name);addstr("\t");addstr(ip);}}
fclose(fpu);
y=y+2;
mvaddstr(y,x,"WindowsUsers");
fpw=fopen(".Wuserlist","r");
while(!feof(fpw)){
y=y+2;
fscanf(fpw,"%s",name);
if(!feof(fpw))mvaddstr(y,x,name);
}
fclose(fpw);
y=y+2;
mvaddstr(y,x,"PressEnterKeytoBack");
ch=getch();
switch(ch){
case'\r':endwin();clear();ConfigUser();
break;
default:
break;
}
}
RestartServer(){
intch;
initial();
box(stdscr,0,0);
attron(A_REVERSE);
mvaddstr(0,20,"RestarttheServer...");
attroff(A_REVERSE);
system("sudo-b/etc/init.d/nfsrestart>.nfsst");
system("sudo-b/sbin/servicesmbrestart>.smbst");
mvaddstr(12,20,"PressEnterKeytoBack");
ch=getch();
switch(ch){
case'\r':endwin();clear();main();
break;
default:
break;
}
}
ChangePW(){
system("sudopasswdtcsadmin");
main();
}
AddUnixUser(){
intx=32,y=6,ch;
charname[16],ip[16];
initial();
box(stdscr,0,0);
attron(A_REVERSE);
mvaddstr(0,20,"AddaUnixUser");
attroff(A_REVERSE);
mvaddstr(6,19,"IPAddress:");
mvaddstr(8,19,"Username:");
mvaddstr(10,19,"");mvaddstr(12,19,"[Apply]");
mvaddstr(14,19,"[Cancel]");
move(y,x);
do{
ch=getch();
switch(ch){
caseKEY_LEFT:if(x>=33elsex=x;
break;
caseKEY_RIGHT:if(x=33)mvaddch(y,--x,'');
break;
case27:endwin();clear();ConfigUser();
break;
default:
if(y==6){
if(x>=32x++;}
}
if(y==8){
if(x>=32x++;}
}
break;
}
move(y,x);
}while(1);
}
AddWindowsUser(){
intx=32,y=8,ch;
charname[16];
initial();
box(stdscr,0,0);
attron(A_REVERSE);
mvaddstr(0,20,"AddaWindowsUser");
attroff(A_REVERSE);
mvaddstr(8,19,"Username:");
mvaddstr(10,19,"");
mvaddstr(12,19,"[Apply]");
mvaddstr(14,19,"[Cancel]");
move(y,x);
do{
ch=getch();
switch(ch){
caseKEY_LEFT:if(x>=33elsex=x;
break;
caseKEY_RIGHT:if(x=33)mvaddch(y,--x,'');
break;
case27:endwin();clear();ConfigUser();
break;
default:
if(y==8){
if(x>=32x++;}
}
break;
}
move(y,x);
}while(1);
}
RemoveUnixUser(){
intx=32,y=6,ch;
charname[16];
initial();
box(stdscr,0,0);
attron(A_REVERSE);
mvaddstr(0,20,"RemoveaUnixUser");
attroff(A_REVERSE);
mvaddstr(6,19,"Username:");
mvaddstr(8,19,"");
mvaddstr(10,19,"[Apply]");
mvaddstr(12,19,"[Cancel]");
move(y,x);
do{
ch=getch();
switch(ch){
caseKEY_LEFT:if(x>=33elsex=x;
break;
caseKEY_RIGHT:if(x=33)mvaddch(y,--x,'');
break;
case27:endwin();clear();ConfigUser();
break;
default:
if(y==6){
if(x>=32x++;}
}
break;
}
move(y,x);
}while(1);
}
intCheckUName(intcol){
intx=32,y=col,r=1,n=0;
charname[20]="",fname[20]="",fip[20]="",tname;FILE*fp;
move(y,x);
name[0]=inch();
if(name[0]>=97
x++;
move(y,x);
tname=inch();
if(tname>=97}while(tname>=97
fp=fopen(".Uuserlist","r");
while(!feof(fp)){
fscanf(fp,"%s",fip);
fscanf(fp,"%s",fname);
if(strcmp(fname,name)==0)r=0;
}
fclose(fp);
}
elser=0;
returnr;
}
intCheckWName(intcol){
intx=32,y=col,r=1,n=0;
charname[20]="",fname[20]="",tname;
FILE*fp;
move(y,x);
name[0]=inch();
if(name[0]>=97
x++;
move(y,x);
tname=inch();
if(tname>=97}while(tname>=97
fp=fopen(".Wuserlist","r");
while(!feof(fp)){
fscanf(fp,"%s",fname);
if(strcmp(fname,name)==0)r=0;
}
fclose(fp);
}
elser=0;
returnr;
}
AddUUser(){
intx=32,y=8,n=0;
charname[20]="",ip[20]="",tname,tip,cmdstr1[50]="",cmdstr2[50]="";
FILE*fp,*fpe;
do{
move(y,x);
tname=inch();
if(tname>=97
x++;
n++;
}while(tname>=97
x=32,y=6,n=0;
do{
move(y,x);
tip=inch();
if(tip==46||(tip>=48
x++;
n++;
}while(tip==46||(tip>=48
fp=fopen(".Uuserlist","a");
fprintf(fp,"%s\t%s\n",ip,name);
fclose(fp);
system("/bin/cat.loopback>.hosts");
system("/bin/cat.Uuserlist>>.hosts");
strcat(cmdstr1,"/bin/mkdir/data/");
strcat(cmdstr1,name);
strcat(cmdstr2,"/bin/chmod777/data/");
strcat(cmdstr2,name);
system(cmdstr1);
system(cmdstr2);
fpe=fopen(".exports","a");
fprintf(fp,"/data/%s\t%s(rw,all_squash,sync)\n/data/%s\t*(ro)\n",name,name,name);
fclose(fpe);
}
AddWUser(){
intx=32,y=8,n=0;
charname[20]="",tname,cmdstr1[50]="",cmdstr2[50]="",cmdstr3[100]="";
FILE*fp,*fpe,*fpo,*fpk;
do{
move(y,x);
tname=inch();
if(tname>=97
x++;
n++;
}while(tname>=97
fp=fopen(".Wuserlist","a");
fprintf(fp,"%s\n",name);
fclose(fp);
strcat(cmdstr1,"sudo-b/usr/sbin/useradd-d/data/tcssam/");
strcat(cmdstr1,name);
strcat(cmdstr1,"-m");
strcat(cmdstr1,name);
strcat(cmdstr2,"sudo/usr/bin/smbpasswd");
strcat(cmdstr2,name);
system(cmdstr1);
getch();
system("/bin/cat/etc/passwd>.smbu");
fpo=fopen(".smbu","r");
while(!feof(fpo)){
fscanf(fpo,"%s",cmdstr3);
}
fclose(fpo);
fpk=fopen(".smbuu","w");
fprintf(fpk,"%s",cmdstr3);
fclose(fpk);
system("sudo-b/bin/cat.smbuu|/usr/bin/mksmbpasswd.sh>>/etc/samba/smbpasswd");
endwin();
system(cmdstr2);
AddWindowsUser();
}
RemoveUUser(){
intx=32,y=6,n=0;
char
name[20]="",tname,fname[20]="",fip[20]="",cmdstr[50]="",namet[50]="",ename[50]=
"",edir[50]="",edir1[50]="",edir2[50]="";
FILE*fp,*fpt,*fp1,*fpt1;
do{
move(y,x);
tname=inch();
if(tname>=97
x++;
n++;
}while(tname>=97
fp=fopen(".Uuserlist","r");
fpt=fopen(".Uuser","a");
while(!feof(fp)){
fscanf(fp,"%s",fip);
fscanf(fp,"%s",fname);
if(strcmp(fname,name)!=0
}
fclose(fpt);
fclose(fp);
system("/bin/cat.Uuser>.Uuserlist");
system("/bin/rm-f.Uuser");
system("/bin/cat.loopback>.hosts");
system("/bin/cat.Uuserlist>>.hosts");
strcat(cmdstr,"/bin/rm-rf/data/");
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 食品添加劑安全性評估與合理使用在調(diào)味品行業(yè)的應(yīng)用報(bào)告
- 小學(xué)教育信息化建設(shè)反思試題及答案
- 教育園區(qū)建設(shè)對2025年社會穩(wěn)定風(fēng)險(xiǎn)評估與風(fēng)險(xiǎn)監(jiān)測報(bào)告
- 機(jī)械裝備制造業(yè)智能化升級與產(chǎn)品質(zhì)量提升研究報(bào)告
- 教師教育教學(xué)改進(jìn)表現(xiàn)的試題及答案
- 小學(xué)教師反思與校本培訓(xùn)的重要性試題及答案
- 山東石油化工學(xué)院《工程管理類軟件應(yīng)用含技術(shù)》2023-2024學(xué)年第一學(xué)期期末試卷
- 工業(yè)互聯(lián)網(wǎng)平臺安全升級之道:2025年漏洞掃描技術(shù)前瞻報(bào)告
- 曲阜遠(yuǎn)東職業(yè)技術(shù)學(xué)院《食品分析含實(shí)驗(yàn)》2023-2024學(xué)年第二學(xué)期期末試卷
- 市政公用工程法律法規(guī)試題及答案
- DB4403T339-2023城市級實(shí)景三維數(shù)據(jù)規(guī)范
- 設(shè)備維護(hù)工程師簡歷
- 2023版押品考試題庫必考點(diǎn)含答案
- 挖孔樁基施工方案(水磨鉆)
- 變電檢修技能考試計(jì)算
- 國際經(jīng)濟(jì)法學(xué)(湘潭大學(xué))智慧樹知到答案章節(jié)測試2023年
- 以案說德發(fā)言四篇
- 大氣污染控制工程課后題答案解析
- 臨床試驗(yàn)倫理委員會倫理審查不同意見溝通的標(biāo)準(zhǔn)操作規(guī)程
- 梅毒診療指南(2023年)
- 高中物理3-3熱學(xué)練習(xí)題(含答案)
評論
0/150
提交評論