帮忙做一道C语言程序设计作业

帮忙做一道C语言程序设计作业,第1张

可以参考

#include "stdioh" /I/O函数/

#include "stdlibh" /其它说明/

#include "stringh" /字符串函数/

#include "conioh" /屏幕 *** 作函数/

#include "memh" /内存 *** 作函数/

#include "ctypeh" /字符 *** 作函数/

#include "alloch" /动态地址分配函数/

struct score

{

int mingci;

char xuehao[8];

char mingzi[20];

float score[6];

}data,info[1000];

int i,j,k=0;

char temp[20],ch;

FILE fp,fp1;

void shuru()

{

if((fp=fopen("s_scoretxt","ab+"))==NULL)

{

printf("cannot open this file\n");

getch();exit(0);

}

for(i=0;i<=1000;i++)

{

printf("\nPlease shuru xuehao:");

gets(dataxuehao);

printf("Please shuru mingzi:");

gets(datamingzi);

printf("Please shuru yuwen score:");

gets(temp);datascore[0]=atof(temp);

printf("Please shuru shuxue score:");

gets(temp);datascore[1]=atof(temp);

printf("Please input yingyu score:");

gets(temp);datascore[2]=atof(temp);

printf("Please shuru wuli score:");

gets(temp);datascore[3]=atof(temp);

printf("Please shur huaxue score:");

gets(temp);datascore[4]=atof(temp);

datascore[5]=datascore[0]+datascore[1]+datascore[2]+datascore[3]+datascore[4];

fwrite(&data,sizeof(data),1,fp);

printf("anothery/n");

ch=getch();

if(ch=='n'||ch=='N')

break;

} fclose(fp);

}

void xianshi()

{

float s;int n;

if((fp=fopen("s_scoretxt","rb+"))==NULL)

{

printf("Cannot reading this file\n");

exit(0);

}

for(i=0;i<=1000;i++)

{

if((fread(&info[i],sizeof(info[i]),1,fp))!=1)

break;

}

printf("\nxuehao mingzi yuwen shuxue yingyu wuli huauxue zhongfen\n");

for(j=0,k=1;j<i;j++,k++)

{

info[j]mingci=k;

printf("%6s %8s %31f %31f %31f %31f %31f %31f\n",info[j]xuehao,info[j]mingzi,info[j]score[0],info[j]score[1],info[j]score[2],info[j]score[3],info[j]score[4],

info[j]score[5]);

}

getch();

fclose(fp);

}

void xiugai()

{

if((fp=fopen("s_scoretxt","rb+"))==NULL||(fp1=fopen("temptxt","wb+"))==NULL)

{

printf("Cannot open this file\n");

exit(0);

}

printf("\nPLease shuru xiugai xuehao:");

scanf("%d",&i); getchar();

while((fread(&data,sizeof(data),1,fp))==1)

{

j=atoi(dataxuehao);

if(j==i)

{

printf("xuehao:%s\nmingzi:%s\n",dataxuehao,datamingzi);

printf("Please shuru mingzi:");

gets(datamingzi);

printf("Please shuru yuwen score:");

gets(temp);datascore[0]=atof(temp);

printf("Please shuru shuxue score:");

gets(temp);datascore[1]=atof(temp);

printf("Please input yingyu score:");

gets(temp);datascore[2]=atof(temp);

printf("Please input wuli score:");

gets(temp);datascore[3]=atof(temp);

printf("Please input huaxue score:");

gets(temp);datascore[4]=atof(temp);

datascore[5]=datascore[0]+datascore[1]+datascore[2]+datascore[3]+datascore[4];

} fwrite(&data,sizeof(data),1,fp1);

}

fseek(fp,0L,0);

fseek(fp1,0L,0);

while((fread(&data,sizeof(data),1,fp1))==1)

{

fwrite(&data,sizeof(data),1,fp);

}

fclose(fp);

fclose(fp1);

}

void chazhao()

{

if((fp=fopen("s_scoretxt","rb"))==NULL)

{

printf("\nCannot open this file\n");

exit(0);

}

printf("\nPLease shuru xuehao chakan:");

scanf("%d",&i);

while(fread(&data,sizeof(data),1,fp)==1)

{

j=atoi(dataxuehao);

if(i==j)

{

printf("xuehao:%s mingzi:%s\nyuwen:%f\n shuxue:%f\n yingyu:%f\n wuli:%f\n huaxue:%f\n ",dataxuehao,datamingzi,datascore[0],datascore[1],datascore[2],datascore[3],datascore[4],datascore[5]);

}getch();

}

}

void shanchu()

{

if((fp=fopen("s_scoretxt","rb+"))==NULL||(fp1=fopen("temptxt","wb+"))==NULL)

{

printf("\nopen scoretxt was failed!");

getch();

exit(0);

}

printf("\nPlease input ID which you want to del:");

scanf("%d",&i);getchar();

while((fread(&data,sizeof(data),1,fp))==1)

{

j=atoi(dataxuehao);

if(j==i)

{

printf("Anykey will delet it\n");

getch();

continue;

}

fwrite(&data,sizeof(data),1,fp1);

}

fclose(fp);

fclose(fp1);

remove("s_scoretxt");

rename("temptxt","s_scoretxt");

printf("Data delet was succesful!\n");

printf("Anykey will return to main");

getch();

}

main()

{

while(1)

{

clrscr(); /清屏幕/

gotoxy(1,1); /移动光标/

textcolor(YELLOW); /设置文本显示颜色为**/

textbackground(BLUE); /设置背景颜色为蓝色/

window(1,1,99,99); / 制作显示菜单的窗口,大小根据菜单条数设计/

clrscr();

printf("welcome to use student manage\n");

printf("menu\n");

printf(" ========================================================= \n");

printf(" 1>shuru 2>xiugai \n");

printf(" 3>shanchu 4>chazhao \n");

printf(" 5>xianshi 6>exit \n");

printf(" \n");

printf(" --------------------------------------------------------- \n");

printf(" Please input which you want(1-6):");

ch=getch();

switch(ch)

{

case '1':shuru();break;

case '2':xiugai(); break;

case '3':shanchu(); break;

case '4':chazhao(); break;

case '5':xianshi(); break;

case '6':exit(0);

default: continue;

}

}

}

第一题:

#include <stdioh>

#include <timeh>

#include <stdlibh>

int main()

{

int i,j, a,b, res, sum=0;

char ch;

printf("Now ready to answer!\nEvery question you have 3 chances to answer, first chance you answer right you can got 10, second got 7, third got 5 Otherwise can not got score!\n");

for(i=0; i<10; i++)

{

printf("%dth question:", i+1);

srand(time(NULL));

a = rand()%50;

b = rand()%(a>25(50-a):a);

ch = rand()%2;

if(ch) ch='+';

else ch='-';

printf("%d %c %d = ", a, ch, b);

for(j=0; j<3; j++)

{

scanf("%d", &res);

if(ch=='+')

if(res==a+b){

printf("right!\n");

switch(j){

case 0: sum+=10;break;

case 1: sum+=7; break;

case 2: sum+=5; break;

}

break;

}

else{

printf("wrong!\n");

if(j!=2)printf("try again:");

}

else

if(res==a-b){

printf("right!\n");

switch(j){

case 0: sum+=10;break;

case 1: sum+=7; break;

case 2: sum+=5; break;

}

break;

}

else{

printf("wrong!\n");

if(j!=2)printf("try again:");

}

}

}

printf("your score is : %d\n", sum);

return 0;

}

/13 bookc源程序/

#include <dosh>

#include <biosh>

#include <conioh>

#include <stdioh>

#include <stdlibh>

#include <mathh>

#define LEFT 0x4b00 /左/

#define RIGHT 0x4d00 /右/

#define DOWN 0x5000 /下/

#define UP 0x4800 /上/

#define SPACE 0x3920 /空格/

#define ESC 0x011b / ESC键/

#define ENTER 0x1c0d /回车键/

#define Backspace 0xe08 /擦除键/

#define ALT_B 12288 /组合键ALT_B /

#define ALT_M 12800/组合键ALT_M /

#define ALT_H 8960/组合键ALT_H /

int key;/按键变量/

int textx,texty;/光标坐标,x行,y列/

struct menustruct/菜单用的结构体/

{

char name[10];/主菜单名/

char str[10][20];/选项/

int n;/选项数/

}ml[3];/使用了3个,可根据需要增删/

typedef struct BookList/书的结构体/

{

char num[20];/图书编号/

char name[20];/书名/

int price;/书的价格/

char person[20];/借阅人/

int yes;/判断书是否存在或者已经借出,1存在,0借出/

struct BookList next;

}Book;

typedef struct MemberList/会员的结构体/

{

char name[20];/会员的姓名/

char sex[2];/会员的性别/

int age;/会员的年龄/

struct MemberList next;

}Member;

char save[4096];/保存文本区域空间/

/char sav1[4096];/

char c[4096];/清屏专用空间/

int i,j;/常用变量/

void Menu();/初始化界面/

void Selectitem();/定义菜单/

void DrawSelectitem();/显示主菜单/

void BlackText(int x,int y,char z);/选中菜单/

void RedText(int x,int y,char z);/正常菜单/

void Run();/具体 *** 作过程/

void DrawMl(int n);/显示下拉菜单/

void MoveMl(int n,int x);/菜单选项的控制/

void Enter(int m,int n);/菜单选项的具体功能/

void BookAdd();/添加图书/

void BookConsult();/图书查询/

void BookDel();/删除图书资料/

void BookBorrow();/借书/

void BookReturn(); /还书/

void MemberAdd(); /增加会员/

void MemberConsult();/查询会员/

void MemberDel(); /删除会员/

void MemberBook(); /查询会员借书信息/

void Help(); /帮助/

void Ver(); /版本信息/

void ClrScr();/自定义清屏函数/

void DrawFrame(int left,int up,int right,int down,int textcolor,int backgroundcolor);/画边框/

/主函数/

void main(void)

{

Menu();/初始化界面/

Run();/具体 *** 作过程/

}

/初始化界面/

void Menu()

{

system("cls"); /调用系统的清屏命令/

textbackground(BLUE);/将背景设置为蓝色/

window(1,1,25,80);

clrscr();

textx=3;/光标初始化位置/

texty=2;

gotoxy(1,2);

printf("%c",218);/画左上角/

for(i=0;i<78;i++)

printf("%c",196); /画水平直线/

printf("%c",191);/画右上角/

for(i=3;i<=23;i++)

{

gotoxy(1,i);

printf("%c",179); /画垂直线/

gotoxy(80,i);

printf("%c",179);

}

printf("%c",192); /画左下角/

for(i=0;i<78;i++)

printf("%c",196);

printf("%c",217); /画右下角/

gotoxy(1,1);

textcolor(7); /设置灰色/

for(i=0;i<80;i++)

cprintf("%c",219);/用符号实现画主菜单的灰色背景区/

Selectitem(); /调用选项函数/

DrawSelectitem(); /画选项/

gettext(2,3,78,23,c); /保存当前文本区域/

}

/定义菜单/

void Selectitem()

{

strcpy(ml[0]name,"Book");/下面的具体选项补空格是为了各菜单黑色背景相同/

strcpy(ml[0]str[0],"Add ");/添加图书/

strcpy(ml[0]str[1],"Consult ");/查询图书/

strcpy(ml[0]str[2],"Del ");/删除图书资料/

strcpy(ml[0]str[3],"Borrow ");/借书/

strcpy(ml[0]str[4],"Return ");/还书/

strcpy(ml[0]str[5],"Exit ");/退出系统/

ml[0]n=6; /保存菜单的项数/

strcpy(ml[1]name,"Member");

strcpy(ml[1]str[0],"Add ");/添加新会员/

strcpy(ml[1]str[1],"Consult ");/查询会员资料/

strcpy(ml[1]str[2],"Del ");/删除会员资料/

strcpy(ml[1]str[3],"Member&book ");

ml[1]n=4;

strcpy(ml[2]name,"Help");/系统帮助/

strcpy(ml[2]str[0],"This System ");

strcpy(ml[2]str[1],"Ver ");

ml[2]n=2;

}

/显示主单名/

void DrawSelectitem()

{

for(i=0;i<3;i++)

RedText(i,1,ml[i]name); /显示主菜单名,且首字母为红色/

}

/正常显示菜单/

void RedText(int x,int y,char z)

{

textbackground(7); /设置背景颜色为浅灰色/

gotoxy(3+x20,y);

for(j=0;z[j];j++)

{

if(j==0)

textcolor(RED);/第一个字母显示红色/

else

textcolor(BLACK); /设置黑色/

cprintf("%c",z[j]); /输出菜单名/

}

}

/显示选中菜单/

void BlackText(int x,int y,char z)

{

textbackground(0); /设置背景颜色为黑色/

textcolor(15); /设置文本颜色为白色/

gotoxy(3+20x,y);/定位坐标/

cputs(z); /输出菜单名字符串/

}

/按键 *** 作过程/

void Run()

{

while(1)

{

gotoxy(texty,textx);

key=bioskey(0);/接收按键/

switch(key)

{

case ALT_B:

case ESC: DrawMl(0);break; /显示下拉菜单1/

case ALT_M: DrawMl(1);break;/显示下拉菜单2/

case ALT_H: DrawMl(2);/显示下拉菜单3/

case UP: /上光标键的 *** 作控制/

{

if(textx==3)

textx=23;

textx--;

gotoxy(texty,textx);

}break;

case DOWN: /下光标键的 *** 作控制/

{

if(textx==23)

textx=3;

textx++;

gotoxy(texty,textx);

}break;

case LEFT: /左光标键的 *** 作控制/

{

if(texty==2)

texty=79;

texty--;

gotoxy(texty,textx);

}break;

case Backspace: /擦除键的设置/

{

if(texty==2&&textx==3)

continue;

else

{

if(texty!=2)

texty--; /擦除键的细节问题,先擦去东西,然后光标还要往后退一格/

else

if(texty==2)

{

texty=78;

textx--;

}

gotoxy(texty,textx);

printf(" ");

gotoxy(texty,textx);

}

}break;/end case 0xe08/

case RIGHT: /右光标键的 *** 作控制/

{

if(texty==79)

texty=2;

texty++;

gotoxy(texty,textx);

}break;

case SPACE: /空格键的 *** 作/

{

if(texty==79)

continue;

else

{

gotoxy(texty,textx); /空格的细节 *** 作/

printf(" ");

texty++;

gotoxy(texty,textx);

}

}break;

case ENTER: /回车的控制 *** 作/

{

if(textx==23)

continue;

textx++;

texty=2;

gotoxy(texty,textx);

}break;

default : /非控制键的结果/

{

if(texty==79&&textx==23)/到达最后就不再输出/

continue;

else

if(texty==79&&textx!=23) /到行的最后/

{

textx++;

texty=2;

}

gotoxy(texty,textx);/输出结果/

printf("%c",key);

if(texty==79) /如果texty==79就不执行/

continue;

else /如果没到行尾就继续执行,使光标向前移动一位/

texty++;

}

}

}/大循环的大括号/

}

/画边框函数/

void DrawFrame(int l,int u,int r,int d,int tcolor,int bcolor)

{

textbackground(bcolor); /背景颜色/

textcolor(bcolor); /文本颜色/

for(i=l;i<=r;i++) /输出背景区域/

{

for(j=u;j<=d;j++)

{

gotoxy(i,j);

printf("%c",219); /输出背景字符/

}

}

textcolor(tcolor);/边框颜色/

for(i=u+1;i<d;i++) /在背景区域内输出边框线/

{

gotoxy(l,i);

cprintf("%c",179); /垂直线/

gotoxy(r,i);

cprintf("%c",179);

}

for(i=l+1;i<r;i++)

{

gotoxy(i,u);

cprintf("%c",196); /水平线/

gotoxy(i,d);

cprintf("%c",196);

}

gotoxy(l,u);

cprintf("%c",218);/左上角/

gotoxy(r,u);

cprintf("%c",191);/右上角/

gotoxy(l,d);

cprintf("%c",192);/左下角/

gotoxy(r,d);

cprintf("%c",217); /右下角/

/ gettext(l+1,u+1,r-1,d-1,save1);//保存边框内区域/

}

/显示具体下拉选择项目/

void DrawMl(int n)

{

gettext(1,1,80,25,save);/保存被掩盖的地方/

BlackText(n,1,ml[n]name);/反选显示主菜单/

DrawFrame(3+20n-1,2,3+20n+19,3+ml[n]n,0,7);/下拉菜单的边框/

for(i=3;i<3+ml[n]n;i++)/输出所选菜单各选项/

{

if(i==3)

BlackText(n,i,ml[n]str[i-3]);/默认选中第一项/

else

RedText(n,i,ml[n]str[i-3]);/其余各项首字符红色显示/

}

gotoxy(79,1);

MoveMl(n,3);/菜单选项的控制/

}

/菜单选项的控制,n决定水平项,x决定下拉的选项/

void MoveMl(int n,int x)

{

int flag=1;

while(flag)

{

gotoxy(79,1);

key=bioskey(0);/接收按键/

gotoxy(79,1);

switch(key)

{

case ESC:/退出循环/

puttext(1,1,80,25,save);/恢复打开菜单前的样子/

flag=0;

break;

case LEFT:/移到左边的选项/

puttext(1,1,80,25,save);/恢复打开菜单前的样子/

if(n==0)/往左移动越界的话移到最后一个选项/

DrawMl(2);

else

DrawMl(n-1);

flag=0;

break;

case RIGHT:/移动右边的选项/

puttext(1,1,80,25,save);/恢复打开菜单前的样子/

if(n==2)/往右移动越界的话移到第一个选项/

DrawMl(0);

else

DrawMl(n+1);

flag=0;

break;

case UP:/具体选项往上移动/

RedText(n,x,ml[n]str[x-3]);/输出红色字体/

if(x==3)/移到最上面再按上键,就移到最下面/

x=3+ml[n]n-1;

else

x--;/移动到新的要显示的内容/

BlackText(n,x,ml[n]str[x-3]);/输出黑色字体/

flag=1;

break;

case DOWN:/具体选项往下移动/

RedText(n,x,ml[n]str[x-3]);

if(x==(3+ml[n]n-1))/移动到最底下再按下键就移到最上面/

x=3;

else

x++;/移动到新的要显示的内容/

BlackText(n,x,ml[n]str[x-3]);

flag=1;

break;

case ENTER:

puttext(1,1,80,25,save);/恢复打开菜单前的样子/

Enter(n,x-3);/菜单选项的具体功能/

flag=0;

break;

}

gotoxy(79,1);

}

}

/菜单选项的具体功能/

void Enter(int m,int n)

{

switch(m)

{

case 0:switch(n) /选择了图书菜单选项/

{

case 0:BookAdd();break;/添加图书/

case 1:BookConsult();break;/图书查询/

case 2:BookDel();break;/删除一本图书资料/

case 3:BookBorrow();break;/借书/

case 4:BookReturn();break;/还书/

case 5:exit(0);break;

} break;/退出系统/

case 1: switch(n) /选择了会员菜单选项/

{

case 0: MemberAdd();break;/添加会员/

case 1: MemberConsult();break;/会员查询/

case 2:MemberDel();break;/删除一个会员资料/

case 3:MemberBook();/查询某个会员所借图书情况/

}break;

case 2:switch(n) /选择了帮助菜单选项/

{

case 0:Help();break;

case 1:Ver();

}

}/结束外switch/

}

#include <windowsh>

#define APPNAME "HELLO_WIN"

char szAppName[] = APPNAME; // 应用程序的名称

char szTitle[]   = APPNAME; // 标题行显示的文字

const char pWindowText;

void CenterWindow(HWND hWnd);

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)

{

    switch (message) {

        case WM_CREATE:

            CenterWindow(hwnd);

            break;

        case WM_DESTROY:

            PostQuitMessage(0);

            break;

        case WM_RBUTTONUP:

            DestroyWindow(hwnd);

            break;

        case WM_KEYDOWN:

            if (VK_ESCAPE == wParam)

                DestroyWindow(hwnd);

            break;

        case WM_PAINT:

        {

            PAINTSTRUCT ps;

            HDC         hdc;

            RECT        rc;

            hdc = BeginPaint(hwnd, &ps);

            GetClientRect(hwnd, &rc);

            SetTextColor(hdc, RGB(240,240,96));

            SetBkMode(hdc, TRANSPARENT);

            DrawText(hdc, pWindowText, -1, &rc, DT_CENTER|DT_SINGLELINE|DT_VCENTER);

            EndPaint(hwnd, &ps);

            break;

        }

        default:

            return DefWindowProc(hwnd, message, wParam, lParam);

    }

    return 0;

}

int APIENTRY WinMain(

        HINSTANCE hInstance,

        HINSTANCE hPrevInstance,

        LPSTR lpCmdLine,

        int nCmdShow

        )

{

    MSG msg;

    WNDCLASS wc;

    HWND hwnd;

    pWindowText = lpCmdLine[0]  lpCmdLine : "这是一个Windows窗体";

    ZeroMemory(&wc, sizeof wc);

    wchInstance     = hInstance;

    wclpszClassName = szAppName;

    wclpfnWndProc   = (WNDPROC)WndProc;

    wcstyle         = CS_DBLCLKS|CS_VREDRAW|CS_HREDRAW;

    wchbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);

    wchIcon         = LoadIcon(NULL, IDI_APPLICATION);

    wchCursor       = LoadCursor(NULL, IDC_ARROW);

    if (FALSE == RegisterClass(&wc))

        return 0;

    hwnd = CreateWindow(

        szAppName,

        szTitle,

        WS_OVERLAPPEDWINDOW|WS_VISIBLE,

        CW_USEDEFAULT,

        CW_USEDEFAULT,

        360,//CW_USEDEFAULT,

        240,//CW_USEDEFAULT,

        0,

        0,

        hInstance,

        0);

    if (NULL == hwnd)

        return 0;

    while (GetMessage(&msg, NULL, 0, 0) > 0) {

        TranslateMessage(&msg);

        DispatchMessage(&msg);

    }

    return msgwParam;

}

void CenterWindow(HWND hwnd_self)

{

    HWND hwnd_parent;

    RECT rw_self, rc_parent, rw_parent;

    int xpos, ypos;

    hwnd_parent = GetParent(hwnd_self);

    if (NULL == hwnd_parent)

        hwnd_parent = GetDesktopWindow();

    GetWindowRect(hwnd_parent, &rw_parent);

    GetClientRect(hwnd_parent, &rc_parent);

    GetWindowRect(hwnd_self, &rw_self);

    xpos = rw_parentleft + (rc_parentright + rw_selfleft - rw_selfright) / 2;

    ypos = rw_parenttop + (rc_parentbottom + rw_selftop - rw_selfbottom) / 2;

    SetWindowPos(

        hwnd_self, NULL,

        xpos, ypos, 0, 0,

        SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE

        );

}

120行,不知道够不够。如果你加上一些注释,可以达到150行。

以上代码,只是显示一行 “这是一个Windows窗体” 的黑色底色的窗体,窗体的标题是“HELLO_WIN”。

1---C

2---B

3---A

4---A

5---C

6---C

7---C

8---C

9---不知道什么意思

10--C

11--C

12--C

13--B

14--B

15--A

16--C

17--C

18--C

19--D

以上就是关于帮忙做一道C语言程序设计作业全部的内容,包括:帮忙做一道C语言程序设计作业、c语言程序设计作业!!急!!、求-c语言程序设计作业。请大家帮帮忙-_-~等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zz/9301460.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-26
下一篇2023-04-26

发表评论

登录后才能评论

评论列表(0条)

    保存