这是一个演示如何
(2)输出每个考生的个人信息,(先输出10个考生的信息)
(3)用函数实现统计各个等级的人数。
其中5000个考生=>数组
考生名字=>字符指针
输入每个考生信息=>循环
#include<stdio.h>#include<stdlib.h>
#include<time.h>
struct _student
{
int id
char *name
char *sex
int score
}students[5000]
void show_student_info(_student s){
printf("考号:%04d\t姓名:%s\t性别:%s\t成绩:%d\n", s.id, s.name, s.sex, s.score)
}
void show_score_info(_student students[]){
int excellent = 0
int pass = 0
int fail = 0
int std1 = 60//及格标准
int std2 = 90//优秀标准
for (int i = 0 i < 5000 i++){
if (students[i].score >= std2)
excellent++
else if (students[i].score >= std1)
pass++
else
fail++
}
printf("优秀人数为:%4d,占 %.2f%%\n", excellent, excellent / 5000.0 * 100)
printf("优秀人数为:%4d,占 %.2f%%\n", pass, pass / 5000.0 * 100)
printf("优秀人数为:%4d,占 %.2f%%\n", fail, fail / 5000.0 * 100)
}
int main(){
//(1)用随机数产生5000个考生信息
srand(time(NULL))
for (int i = 0 i < 5000 i++){
students[i].id = i
students[i].name = "考生"
students[i].sex = rand() % 2 == 0 ? "男" : "女"
students[i].score = rand() % 100
}
//(2)输出每个考生的个人信息,(先输出10个考生的信息)
printf("每个考生的个人信息如下(先输出10个):\n")
int student_count = 10//先输入10个
for (int i = 0 i < student_count i++){
show_student_info(students[i])
}
printf("\n")
//(3)用函数实现统计各个等级的人数。
show_score_info(students)
getchar()
return 0
}
望采纳~
这是我从前写的键盘模拟程序。具体功能见里面的英文说明。下面主函数 调用 只是 一个模拟 例子, 执行了抓取频幕,
并存放为 keyb_tmp.bmp
其它例子 注解掉了。去掉 // 就可执行。
编译器 MS VC++ 6.0
完整含说明,详细程序。(哦,字数超出,不让贴,不得不删去 一点说明)
/* ================================================*
* simu_keyboard.c
* Ji Zhang Jun-27-2006
* ---------------------------------------------------
* Function Syntax
* ---------------------------------------------------
* something can be done by such tech
* Send Screen_Capture, Window_Capture to clipboard.
* GetDIBits() can chose begin and end row number
* get mouse location on Desk Top ?
* ---------------------------------------------------
* Short-Cut key simulations:
* minimize all windows "windows + D" or "windows + M"
* cancel minimize windows "shift + window + M
* Alt+Backspace or CTRL+Z cancel previous op
* Alt+Shift+Backspace re-do the canceled op
* Alt+ESC active next window
* ===============================
void keybd_event(BYTE bVirtualKey, BYTE bScanCode,
DWORD dwFlags, DWORD dwExtraInfo)
bVirtualKey:
VK_NUMPAD7 0x67 VK_BACK 0x08
VK_NUMPAD8 0x68 VK_TAB 0x09
VK_NUMPAD9 0x69 VK_RETURN 0x0D
VK_MULTIPLY 0x6A VK_SHIFT 0x10
VK_ADD 0x6B VK_CONTROL 0x11
VK_SEPARATOR 0x6C VK_MENU 0x12
VK_SUBTRACT 0x6D VK_PAUSE 0x13
VK_DECIMAL 0x6E VK_CAPITAL 0x14
VK_DIVIDE 0x6F VK_ESCAPE 0x1B
VK_F1 0x70 VK_SPACE 0x20
VK_F2 0x71 VK_END 0x23
VK_F3 0x72 VK_HOME 0x24
VK_F4 0x73 VK_LEFT 0x25
VK_F5 0x74 VK_UP 0x26
VK_F6 0x75 VK_RIGHT 0x27
VK_F7 0x76 VK_DOWN 0x28
VK_F8 0x77 VK_PRINT 0x2A
VK_F9 0x78 VK_SNAPSHOT 0x2C
VK_F10 0x79 VK_INSERT 0x2D
VK_F11 0x7A VK_DELETE 0x2E
VK_F12 0x7B VK_LWIN 0x5B
VK_NUMLOCK 0x90 VK_RWIN 0x5C
VK_SCROLL 0x91 VK_NUMPAD0 0x60
VK_LSHIFT 0xA0 VK_NUMPAD1 0x61
VK_RSHIFT 0xA1 VK_NUMPAD2 0x62
VK_LCONTROL 0xA2 VK_NUMPAD3 0x63
VK_RCONTROL 0xA3 VK_NUMPAD4 0x64
VK_LMENU 0xA4 VK_NUMPAD5 0x65
VK_RMENU 0xA5 VK_NUMPAD6 0x66
================
bScanCode (use break code):
// Simulating a Alt+Tab keystroke
keybd_event(VK_MENU,0xb8,0 , 0)//Alt Press
keybd_event(VK_TAB,0x8f,0 , 0)// Tab Press
keybd_event(VK_TAB,0x8f, KEYEVENTF_KEYUP,0)// Tab Release
keybd_event(VK_MENU,0xb8,KEYEVENTF_KEYUP,0)// Alt Release
* ---------------------------------------------------
* SendInput() may do the same work
* ==============================================*/
#include <Windows.h>
#include <Winuser.h>
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>
#include <time.h>
#define DEBUG 1
#pragma comment (lib, "User32.lib")
#pragma comment (lib, "Gdi32.lib")
void snapscreen_2_clipboard()
void snapwin_2_clipboard()
int get_mousebt_status()
void wait ( int m_seconds)
void simu_notepad()
void do_action(unsigned char action)
// dib functions
int GetBytesPerPixel(int depth)
int GetBytesPerRow(int width, int depth)
int GetBitmapBytes(int width, int height, int depth)
void save_clipboard_img_to_bmp()
FILE *fout
main(int argc, char * argv[])
{
int i=0,j=0
int px,py
time_t now
unsigned char action
char buf[256]
// (void) do_action(0x44)
// following 3 calls for screen capture and save to bmp
(void) snapscreen_2_clipboard()
(void) wait(1000)
(void) save_clipboard_img_to_bmp()
// show exploer: (void) do_action(0x45) // works
// show file finder: (void) do_action(0x46) //works
// minimize all windows: (void) do_action(0x4d) // good
// show run command: (void) do_action(0x52) // Start->Run
// show start menu: (void) do_action(0x5B) // left mouse press Start
// show windows help: (void) do_action(0x70) // display "help center"
// Go on Standby: (void) do_action(0x5e)// do nothing
// simu_notepad()
/* -------------------------------------------------------
test mouse
press and release a BT, return the location and BT id
1 = Left 2=Right 3=Mid, [px,py] screen coords
* -------------------------------------------------------*/
/*---
while (i <40 ) {
j = get_mousebt_status(&px,&py)
if (j >0) while (get_mousebt_status(&px,&py) !=0 ) {}
if ( j >0) {
printf("%d: x=%d y=%d at ",j,px,py )
time(&now)
printf("%s",ctime(&now))
}
i = i + j
}
*---*/
exit(0)
}
/* ------------------------------------------------ *
* void do_action(unsigned char action)
* action can be 0x45 0x46 0x4d 0x52 0x5b 0x70 0x5e
* -------------------------------------------------*/
void do_action(unsigned char action){
keybd_event(VK_LWIN,0,0,0)
keybd_event(action,0,0,0)
keybd_event(VK_LWIN,0,KEYEVENTF_KEYUP,0)
}
/* -------------------------------
* similar to system("notepad")
* typing letters
* ------------------------------*/
void simu_notepad()
{
/*
keybd_event(VkKeyScan('N'),1,0,0) keybd_event(VkKeyScan('N'),1,KEYEVENTF_KEYUP,0)
keybd_event(VkKeyScan('O'),0x98,0,0) keybd_event(VkKeyScan('O'),0x98,KEYEVENTF_KEYUP,0)
keybd_event(VkKeyScan('T'),0x94,0,0) keybd_event(VkKeyScan('T'),0x94,KEYEVENTF_KEYUP,0)
keybd_event(VkKeyScan('E'),0x92,0,0) keybd_event(VkKeyScan('E'),0x92,KEYEVENTF_KEYUP,0)
keybd_event(VkKeyScan('P'),0x99,0,0) keybd_event(VkKeyScan('P'),0x99,KEYEVENTF_KEYUP,0)
keybd_event(VkKeyScan('A'),0x9E,0,0) keybd_event(VkKeyScan('A'),0x9E,KEYEVENTF_KEYUP,0)
keybd_event(VkKeyScan('D'),0xA0,0,0) keybd_event(VkKeyScan('D'),0xA0,KEYEVENTF_KEYUP,0)
keybd_event(VK_RETURN,1,0,0)
keybd_event(VK_RETURN,1,KEYEVENTF_KEYUP,0)
*/
// keybd_event(VkKeyScan('C'),1,0,0) keybd_event(VkKeyScan('C'),1,KEYEVENTF_KEYUP,0)
// keybd_event(VkKeyScan('M'),1,0,0) keybd_event(VkKeyScan('M'),1,KEYEVENTF_KEYUP,0)
// keybd_event(VkKeyScan('D'),1,0,0) keybd_event(VkKeyScan('D'),1,KEYEVENTF_KEYUP,0)
// keybd_event(VK_RETURN,1,0,0)
// keybd_event(VK_RETURN,1,KEYEVENTF_KEYUP,0)
}
/* ------------------------------------------
* get mouse left and right button status
* if left down = 1
* if right down = 2
* else 0 -- up
* if GetAsyncKeyState(VK_RBUTTON) == 0 then UP
* if GetAsyncKeyState(VK_RBUTTON) != 0 then down
* down: ffff8000
* cmd catchs the left button !
* this can catch mouse outside of current window
BOOL GetCursorPos( LPPOINT lpPoint // cursor position )
POINT ptGetCursorPos(&pt)
return mouse BT status:
Left-down=1,right-down=2,mid-down=3,up=0
return mouse position on Desk Top: [x,y]
* ------------------------------------------*/
int get_mousebt_status(int *x, int *y ){
int st
short int b1,b2,b3
POINT pt
GetCursorPos(&pt) // always to get mouse position
*x = pt.x*y = pt.y // return mouse position
st = b1 = b2 = b3 = 0
b1 = 0x8000 &GetAsyncKeyState(VK_LBUTTON)
b2 = 0x8000 &GetAsyncKeyState(VK_RBUTTON)
b3 = 0x8000 &GetAsyncKeyState(VK_MBUTTON)
if ( b1 != 0 ) st = 1 // if left button down, return 1
if ( b2 != 0 ) st = 2 // if right button down, return 2
if ( b3 != 0 ) st = 3 // if mid button down, return 3
return st
}
void wait ( int m_seconds )
{
clock_t endwait
endwait = clock () + m_seconds// * CLK_TCK
while (clock() <endwait) {}
}
/* ----------------------------------
simulation of Alt-PrintScreen
to get current Window image in clipboard
Ji Zhang 2006-May-23
* -----------------------------------*/
void snapwin_2_clipboard()
{
keybd_event(VK_LMENU,0xA4,0,0)
keybd_event(VK_SNAPSHOT,0x2C,0,0)
keybd_event(VK_SNAPSHOT,0x2C,KEYEVENTF_KEYUP,0)
keybd_event(VK_LMENU,0xA4,KEYEVENTF_KEYUP,0)
}
/* ----------------------------------
simulation of PrintScreen
to get current Desk Top image in clipboard
Ji Zhang 2006-May-23
* -----------------------------------*/
void snapscreen_2_clipboard()
{
keybd_event(VK_SNAPSHOT,0x2C,0,0)
keybd_event(VK_SNAPSHOT,0x2C,KEYEVENTF_KEYUP,0)
}
/* --------------------------------------------------------------
* dib
int GetBytesPerPixel(int depth)
int GetBytesPerRow(int width, int depth)
int GetBitmapBytes(int width, int height, int depth)
* --------------------------------------------------------------*/
int GetBytesPerPixel(int depth)
{ return (depth==32 ? 4 : 3)
}
int GetBytesPerRow(int width, int depth)
{
int bytesPerPixel = GetBytesPerPixel(depth)
int bytesPerRow = ((width * bytesPerPixel + 3) &~3)
return bytesPerRow
}
// bmi.bmiHeader.biWidth, bmi.bmiHeader.biHeight, bmi.bmiHeader.biBitCount
int GetBitmapBytes(int width, int height, int depth)
{
return height * GetBytesPerRow(width, depth)
}
void save_clipboard_img_to_bmp()
{
char nameout[80]
HANDLE h_bitmap,h_dib
BITMAPINFO bmi
HDC hDC
int imageBytes
BITMAPFILEHEADER hdr
int scanLineCount
unsigned char *img
if (!OpenClipboard(NULL)) {
printf("Can not open clipboard\n")
exit(0)
}
if (DEBUG ==1) printf("pass open clipboard\n")
// HANDLE GetClipboardData(UINT uFormat)
h_bitmap = GetClipboardData(CF_BITMAP)
h_dib = GetClipboardData(CF_DIB)
if (h_bitmap ==NULL || h_dib ==NULL){
printf("I got NULL bitmap: ")
} else { printf("I got bitmap: ")}
memcpy(&bmi,h_dib,sizeof(bmi))
printf("%d x %d \n",bmi.bmiHeader.biWidth, bmi.bmiHeader.biHeight)
hDC = CreateCompatibleDC(NULL) // Gdi32.lib.
CloseClipboard()
bmi.bmiHeader.biCompression = BI_RGB
// possible to use part of imgage with img_w,img_h
imageBytes = GetBitmapBytes(bmi.bmiHeader.biWidth, bmi.bmiHeader.biHeight, bmi.bmiHeader.biBitCount)
printf("pass GetBitmapBytes=%d \n",imageBytes)
img = (char *) malloc(imageBytes)
if (!img) {
printf("No enought memory for img !\n")exit(0)
}
// BITMAPFILEHEADER hdr
hdr.bfType = ((WORD) ('M' <<8) | 'B') // is always "BM"
hdr.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)
+ (bmi.bmiHeader.biClrUsed * sizeof(RGBQUAD)) + bmi.bmiHeader.biSizeImage
hdr.bfReserved1 = 0
hdr.bfReserved2 = 0
hdr.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)
+ (bmi.bmiHeader.biClrUsed * sizeof(RGBQUAD))
scanLineCount = GetDIBits(hDC,h_bitmap,0,bmi.bmiHeader.biHeight, img, &bmi, DIB_RGB_COLORS)
strcpy(nameout,"keyb_tmp.bmp")
if ( (fout = fopen(nameout,"wb") ) == NULL ) {
printf("\007Cann't open output file: %s ", nameout)exit(1)
}
fwrite( &hdr, sizeof(BITMAPFILEHEADER ), 1, fout )
fwrite( &bmi, sizeof(BITMAPINFO), 1, fout )
fwrite( img, sizeof(unsigned char),imageBytes, fout )
fclose(fout)
printf("Output in %s\n",nameout)
}
/* ----------------------------end dib and bmp -------------------- */
我正在做的一个实训项目~~~先给你这些代码,如果需要,我还有其他的O(∩_∩)O~
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#define NULL 0
#define LEN sizeof(struct commodity)
#define NAME "commodity by liuchang.txt"
struct commodity
{
char code[10]
char name[15]
int num
int kucun
int mingci
struct commodity *next
}*head,*s
int n=0
char choice //储存选择的选项
FILE *fp
/// 表格 ///
void list()
void list_1()
void list_2()
void list_3()
void list_3_1()
void list_3_2()
void list_3_3()
void list_5()
/// 函数 ///
void read()//读取
struct commodity *add() //添加
struct commodity *qurcode() //按条码号查找
struct commodity *qurname() //按姓名查找
void modify_code(struct commodity *p) //按条码号修改
void modify_name(struct commodity *p) //按姓名修改
void del_code(struct commodity *p) //按条码号删除
void del_name(struct commodity *p) //按姓名删除
//void selectsort_code() //按条码号排序
//void selectsort_name() //按姓名排序
void selectsort_num() //按销售量排序
void tongji() //统计
void save() //保存
void print() //显示
void autoread() //自动读取
#include <windows.h>
int WINAPI WinMain (HINSTANCE hInstance,
HINSTANCE hPrevInstance,
PSTR szCmdLine,
int iCmdShow)
{
MessageBox (NULL, "Hello", "Hello Demo", MB_OK)
return (0)
}
/////////////////////////////////////////////////////////// 表头 ///////////////////////////////////////////////////
void main()//表头
{
system("color b0")
head=(struct commodity*)malloc(LEN)
head->next=NULL
autoread()
do
{
list()
fflush(stdin)
scanf("%s",&choice)
fflush(stdin)
switch(choice)
{
way_1:
case '1':
do
{
list_1()
fflush(stdin)
choice=getchar()
switch(choice)
{
case '1':goto way_1
case '2':goto way_2
case '3':goto way_3
case '4':goto way_4
case '5':goto way_5
case 'a':
read()fflush(stdin)getchar()break
case 'b':
add()break
}
}while(choice!='0')break
way_2:
case '2':
do
{
list_2()
fflush(stdin)
choice=getchar()
switch(choice)
{
case '1':goto way_1
case '2':goto way_2
case '3':goto way_3
case '4':goto way_4
case '5':goto way_5
case 'a':
qurcode()break
case 'b':
qurname()break
}
}while(choice!='0')break
way_3:
case '3':
do
{
list_3()
fflush(stdin)
choice=getchar()
switch(choice)
{
case '1':goto way_1
case '2':goto way_2
case '3':goto way_3
case '4':goto way_4
case '5':goto way_5
way_3_1:case 'a':
{
do
{
list_3_1()
fflush(stdin)
choice=getchar()
switch(choice)
{
case '1':goto way_1
case '2':goto way_2
case '3':goto way_3
case '4':goto way_4
case '5':goto way_5
case 'a':
list_3_1()break
case 'A':
modify_code(qurcode())break
case 'B':
modify_name(qurname())break
case 'b':goto way_3_2
case 'c':goto way_3_3
}
}while(choice!='0')break
}
way_3_2:case 'b':
{
do
{
list_3_2()
fflush(stdin)
choice=getchar()
switch(choice)
{
case '1':goto way_1
case '2':goto way_2
case '3':goto way_3
case '4':goto way_4
case '5':goto way_5
case 'a':goto way_3_1
case 'b':
list_3_2()
case 'A':
del_code(qurcode())break
case 'B':
del_name(qurname())break
case 'c':goto way_3_3
}
}while(choice!='0')break
}
way_3_3:case 'c':
{
do
{
list_3_3()
fflush(stdin)
choice=getchar()
switch(choice)
{
case '1':goto way_1
case '2':goto way_2
case '3':goto way_3
case '4':goto way_4
case '5':goto way_5
case 'a':goto way_3_1
case 'b':goto way_3_2
case 'c':
list_3_3()break
//case 'A':
//selectsort_code()break
//case 'B':
// selectsort_name()break
case 'C':
selectsort_num()break
}
}while(choice!='0')break
}
}
}while(choice!='0')break
way_4:
case '4': fflush(stdin)
tongji()break
way_5:
case '5':
do
{
list_5()
fflush(stdin)
choice=getchar()
switch(choice)
{
case '1':goto way_1
case '2':goto way_2
case '3':goto way_3
case '4':goto way_4
case '5':goto way_5
case 'a':
save()break
case 'b':
print()break
}
}while(choice!='0')break
case '0': exit(0)break
default: printf("\t\t输入数据错误!\n")
}
}while(1)
}
void list()
{
system("cls")
system("color a0")
printf("\t\t======== 商 品 销 售 管 理 系 统 ========\n")
printf("\t\t\t1...输入信息\n\n")
printf("\t\t\t2...查询信息\n\n")
printf("\t\t\t3...更新信息\n\n")
printf("\t\t\t4...统计信息\n\n")
printf("\t\t\t5...输出信息\n\n")
printf("\t\t\t0... 退出 \n\n")
printf("\t\t\t\t\t\t共有%3d个记录\n",n)
printf("\t~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~\n")
printf(" \t\t\t\t\t刘昶IT作品 09测试02班\n")
printf("\t请选择:")
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)