A. 关于c语言课题设计(学生信息管理系统)
#include"stdio.h"
#include"stdlib.h"
#include"string.h"
#include"conio.h"
typedef struct Student
{char name[20];
char num[20];
int score;
Student *next;
}student;
student *creat()
{student *head;student *p,*s;int flag=1;
head=(student*)malloc(sizeof(student));p=(student*)malloc(sizeof(student));
head->next=p;
if(!p){printf("失败");return 0;}
printf("输入姓名:");gets(p->name);
printf("输入学号:");scanf("%s",p->num);
printf("输入成绩:");scanf("%d",&p->score);
while(flag)
{s=(student*)malloc(sizeof(student));
getchar();
printf("输盯肢入姓名:(输入0退出):");gets(s->name);
if(!strcmp(s->name,"0")){flag=0;break;}
printf("输入学号:");scanf("%s",s->num);
printf("输入成绩:");scanf("%d",&s->score);
p->next=s;
p=s;
}
p->带滑next=NULL;
return head;
}
void listprint(student *head)
{student *p;
p=head->next;
while(p)
{printf("姓名:%s\n学号:%s\n成绩:%d\n",p->name,p->num,p->score);
p=p->next;
}
}
void listfind(student *head,char str[])
{student *p;p=head->next;
if(p)
{
while(p&&(strcmp(p->name,str)&&strcmp(p->num ,str)))
p=p->next;
if(p){ printf("姓名:%s\n学号:%s\n成绩:%d\n",p->凯行世name,p->num,p->score);}
else printf("没有该学生信息!\n");
}
}
void listadd(student *head)
{student *p,*s;int flag=1;
p=head->next;
while(p->next!=NULL)p=p->next;
while(flag)
{s=(student*)malloc(sizeof(student));
printf("输入姓名:(输入0退出):");gets(s->name);
if(!strcmp(s->name,"0")){ flag=0;break;}
printf("输入学号:");scanf("%s",s->num);
printf("输入成绩:");scanf("%d",&s->score);
p->next=s;
p=s;
getchar();
}
p->next=NULL;
}
void listdel(student *head,char str[])
{student *p1,*p2;p2=head;
p1=head->next;
while(p1&&(strcmp(p1->name,str)&&strcmp(p1->num ,str)))
{p2=p1;p1=p1->next;}
if(!p1)printf("\n\n\n\n\t 没有该学生的信息\n");
else {p2->next=p1->next;printf("\n\n\n\n\n\t\t\t\t 删除成功!\n\n");free(p1);}
}
void listsort(student *head)
{student *p1,*p2,*p3,*p4,*temp;temp=(student *)malloc(sizeof(student));
p1=p2=head->next;
for(;p1!=NULL;p1=p1->next)
{p2=p3=p1;p4=p3;
for(;p3!=NULL;p3=p3->next)
{
if(p3->score>p4->score){p4=p3;}
}strcpy(temp->name,p2->name);strcpy(temp->num,p2->num);temp->score=p2->score;
strcpy(p2->name,p4->name);strcpy(p2->num,p4->num);p2->score=p4->score;
strcpy(p4->name,temp->name);strcpy(p4->num,temp->num);p4->score=temp->score;}}
void menu()
{printf("\n\n\n\n\t\t\t菜单\n\t\t\t\n\t\t\t请选择\n\t\t\t********************\n\t\t\t*1创建资料\n\t\t\t*2查找\n\t\t\t*3显示全部\n\t\t\t*4添加\n\t\t\t*5删除\n\t\t\t*6排名\n\t\t\t*7退出\n\t\t\t********************\n");
}
int main()
{student *head;char str[20],ch; int count=0;
while(1)
{menu();ch=getch();
system("cls");
if(ch!='1'&&ch!='7'&&count==0){printf("\n\n\n\n\n\n\t\t\t 你还没有创建资料\n");printf("\n\t\t 按任意键回主菜单\n");getch();system("cls");continue;}
else count=1;
switch(ch)
{case '1':head=creat();break;
case '2':printf("输入要查找的姓名或学号:");gets(str);listfind(head,str);break;
case '3':listprint(head);break;
case '4':listadd(head);break;
case '5':printf("输入要删除的姓名或学号:");gets(str);listdel(head,str);break;
case '6':listsort(head);listprint(head);break;
case '7':printf("\n\n\n\n\n\n\t\t\t 谢谢使用\n\n\n\n\n");getchar();return 0;
}printf("\n\t\t 按任意键回主菜单\n");getch();system("cls");
}
}
B. c语言课设小型图书管理系统设计(c++)
试着做了下这个题,结果和你一样前7项全解决了,就剩下第八个了,明天再试试,能做出来给你发代码。要是我做不出来,还请你给我指点一二。
/*终于完成了,第八项也OK了。
你自己多运则指行几组数据测试下,应该没问题了
*/
// 20130718.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <string>
#include <iomanip>
#include <iostream>
using namespace std;
#define N 5
void swap(string & a,string & b)
{
string c= a;
a= b;
b= c;
}
void swap1(int & a,int & b)
{
int c=a;
a=b;
b=c;
}
class A
{
private:
string name[N];
string writer[N];
int num1[N];//书号
int price[N];
int num2[N];//数量
public:
void input();
void add();
void modify();
void cut();
void look();
void seek();
void display();
};
void A::input()
{
for(int i=0;i<N;i++)
{
int j;
cout<<"请依次输入书名,作者,编号,单价及数量,用空格键分开"<<endl;
cin>>name[i];
cout<<"书名录入成功"<<endl;
cin>>writer[i];
cout<<"作者录入成功"<<endl;
cin>>num1[i];
cout<<"编号录入成功"<<endl;
cin>>衫卖price[i];
cout<<"单价录入成功"<<endl;
cin>>num2[i];
cout<<"数量录入成功"<<endl;
cout<<"是或盯逗否继续输入"<<endl;
cout<<"1:继续"<<endl;
cout<<"2:退出"<<endl;
cin>>j;
if(j==1) ;
else break;
}
}
void A::add()
{
for(int i=0;i<N;i++)
{
if(name[i]==writer[i])
{
int j;
cout<<"请依次输入书名,作者,编号,单价及数量,用空格键分开"<<endl;
cin>>name[i];
cout<<"书名录入成功"<<endl;
cin>>writer[i];
cout<<"作者录入成功"<<endl;
cin>>num1[i];
cout<<"编号录入成功"<<endl;
cin>>price[i];
cout<<"单价录入成功"<<endl;
cin>>num2[i];
cout<<"数量录入成功"<<endl;
cout<<"添加成功,是否继续添加"<<endl;
cout<<"1:是"<<endl;
cout<<"2:否"<<endl;
cin>>j;
if(j==1);
else break;
}
}
}
void A::modify()
{
int i,j;
cout<<"请输入要修改书的书号"<<endl;
cin>>j;
for(i=0;i<N;i++)
{
if(num1[i]!=j);
else
cout<<"书籍已找到"<<endl;
cout<<"请重新输入书名,作者,编号,单价及数量,用空格键分开"<<endl;
cin>>name[i];
cout<<"书名录入成功"<<endl;
cin>>writer[i];
cout<<"作者录入成功"<<endl;
cin>>price[i];
cout<<"单价录入成功"<<endl;
cin>>num2[i];
cout<<"数量录入成功"<<endl;
break;
}
}
void A::cut()
{
int i,j;
cout<<"请输入要删除的书的书号"<<endl;
cin>>j;
for(i=0;i<N;i++)
{
if(num1[i]==j)
{ name[i]=writer[i]=" ";
num1[i]=price[i]=num2[i]=0;
cout<<"初始化完成"<<endl;
break;
}
}
}
void A::look()
{
int i;
for(i=0;i<N;i++)
{
cout<<name[i]<<writer[i]<<num1[i]<<price[i]<<num2[i]<<endl;
}
}
void A::seek()
{
int i,j;
cout<<"请输入要查找的书的书号"<<endl;
cin>>j;
for(i=0;i<N;i++)
{
if(j==num1[i])
cout<<num1[i]<<name[i]<<writer[i]<<price[i]<<num2[i]<<endl;
else
break;
}
}
void A::display()//排序未解决,难。。。。。
{
int i,j,k/*,P,N1,N2*/;
for(i=1;i<N;i++)
{
for(j=0;j<i;j++)
{
if(price[i]>price[j])
{
swap1(price[i],price[j]);
swap(name[i],name[j]);
swap(writer[i],writer[j]);
swap1(num1[i],num1[j]);
swap1(num2[i],num2[j]);
}
}
}
for(k=0;k<N;k++)
{
cout<<setw(5)<<price[k]<<setw(10)<<name[k]<<setw(5)<<writer[k]<<setw(3)<<num1[k]<<setw(3)<<num2[k]<<endl;
}
cout<<"排序完成"<<endl;
}
int main()
{
A a;
int i;
do
{
cout<<"1:信息录入"<<endl;
cout<<"2:添加记录"<<endl;
cout<<"3:信息修改"<<endl;
cout<<"4:信息删除"<<endl;
cout<<"5:信息浏览"<<endl;
cout<<"6:信息查询"<<endl;
cout<<"7:信息排序"<<endl;
cout<<"8:退出系统"<<endl;
cin>>i;
switch(i)
{
case 1:a.input();break;
case 2:a.add();break;
case 3:a.modify();break;
case 4:a.cut();break;
case 5:a.look();break;
case 6:a.seek();break;
case 7:a.display();break;
case 8:cout<<"成功退出"<<endl;break;
default:cout<<"输入错误"<<endl;
}
}while(i!=8);
return 0;
}
/*终于完成了,第八项也OK了。
你自己多运行几组数据测试下,应该没问题了
*/
C. c语言设计
#include<stdio.h>
#include<conio.h>
bool IsOddEven(int value)
{
bool t=true;
int n,i;
i = value%2;
while(value)
{
value /= 10;
n = value%2;
if(n != (++i %2))
{
t = false;
break;
}
}
return t;
}
void main()
{
int t;
printf("请闭穗输入一个整数:");
scanf("%d",&t);
if(IsOddEven(t))
printf("yes\n");
else
printf("轿顷卜no\乎孙n");
}
D. C语言程序设计
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#defineMAX_NUM50
#defineMAX_LINE256
structstudent{
charname[10];
floatmath;
姿尺卖floatchinese;
floateng;
floataver;
chargrade;
};
constchar*student_file="student.txt";
constchar*grade_file="grade.txt";
intinit(structstudent*s,intn);
intfun(structstudents[],intn);
voidsort(structstudent*s,intn);
voiddisplay(structstudent*s,intn);
voidsave_student(structstudent*s,intn,constchar*file);
voidload_student(constchar*file);
intmain(intargc,char*argv[])
{
intnum=0;
structstudentst[MAX_NUM];
num=init(st,MAX_NUM);
printf(" 等级为D的人数:%d ",fun(st,num));
save_student(st,num,student_file);
sort(st,num);
save_student(st,num,grade_file);
display(st,num);
printf(" 所有学生信息 ");
load_student(student_file);
printf(" 排序后的学生信息 ");
load_student(grade_file);
return0;
}
/*初始化*/
intinit(structstudent*s,intn)
{
intnum=0,i=0;
if(0==s||0>=n||MAX_NUM<n)
return0;
printf("请输入学生数量[不大于50]:");
fflush(stdout);
scanf("%d",&num);
while(0>=num||n<num)
{
fflush(stdin);
printf("无效的参数,请输入学生数量[不大于50]:");
fflush(stdout);
scanf("%d",&num);
}
for(i=0;i<num;++i)
{
printf("请输入第%d个学生的信息:",i+1);
fflush(stdout);
scanf("%9s%f%f%f",s[i].name,&s[i].math,&s[i].chinese,&s[i].eng);
fflush(stdin);
}
returnnum;
}
/*计算平均成绩并统计等级为D的人数*/
intfun(structstudents[],intn)
{
inti=0,cnt=0;
if(0==s||0>=n||MAX_NUM<n)
return0;
for(i=0;i<n;++i)
{
s[i].aver=(s[i].math+s[i].chinese+s[i].eng)/3.0;
if(70<=s[i].aver&&85>s[i].aver)
s[i].grade='B';
elseif(60<=s[i].aver&&70>s[i].aver)
s[i].grade='C';
elseif(60>s[i].aver)
s[i].grade='D';
else
s[i].grade='A';
if('D'==s[i].grade)
迹逗++cnt;
}
returncnt;
}
/*降序排列*/
voidsort(structstudent*s,intn)
{
inti=0,j=0;
structstudenttmp;
if(0==s||0>=n||MAX_NUM<n)
return0;
for(i=困慧0;i<n-1;++i)
{
for(j=0;j<n-1-i;++j)
{
if(s[j].aver<s[j+1].aver)
{
tmp=s[j];
s[j]=s[j+1];
s[j+1]=tmp;
}
}
}
}
voiddisplay(structstudent*s,intn)
{
inti=0;
if(0==s||0>=n||MAX_NUM<n)
return0;
printf("所有学生的信息如下: ");
for(i=0;i!=n;++i)
{
printf("%d.name[%s]math[%.1f]chinese[%.1f]eng[%.1f]aver[%.1f]grade[%c] ",
i+1,s[i].name,s[i].math,s[i].chinese,s[i].eng,s[i].aver,s[i].grade);
}
}
/*保存学生信息到指定文件*/
voidsave_student(structstudent*s,intn,constchar*file)
{
inti=0;
FILE*fp=0;
charbuf[MAX_LINE]={0};
if(0==s||0>=n||MAX_NUM<n||0==file)
return0;
if(fp=fopen(file,"w"))
{
for(i=0;i!=n;++i)
{
sprintf(buf,"%s%.1f%.1f%.1f%.1f%c ",
s[i].name,s[i].math,s[i].chinese,s[i].eng,s[i].aver,s[i].grade);
fwrite(buf,1,strlen(buf),fp);
memset(buf,0x00,MAX_LINE);
}
fclose(fp);
}
}
/*加载指定文件中的信息*/
voidload_student(constchar*file)
{
charbuf[MAX_LINE]={0};
FILE*fp=0;
if(0==file)
return;
if(fp=fopen(file,"r"))
{
while(fgets(buf,MAX_LINE,fp))
printf("%s",buf);
fclose(fp);
}
}
E. 求C语言的程序设计
#include<stdio.h>
int main()
{
float a,b,c;
printf("请输入三个实数:\n");
scanf("%f%f%f",&a,&b,&c);
if(a+b<c || a+c<b || b+c<a)
{
printf("0\枝搭n");
}
else
{
if(a==b==c)
printf("1\n");
else if(a==b || b==c || c==a)
printf("2\庆戚n");
else printf("誉搭陵3\n");
}
return 0;
}
F. 运用C语言中有关内容,独立设计上述游戏,并编程实现以下功能
************************************
#include "iostream.h"
#include<string.h>
#include <stdlib.h>
#include <ctime>
#include<conio.h>
int temp,ying,shu,ping;
int main1(int n1)
{
srand((unsigned)time(0));
n1=rand()%3;
return n1;
}
int main()
{
int now1;
now1=0;
cout<<"--------------------------------------------\n";
cout<<"----------- ---------------\n";
cout<<"----------- LuinSoftware ---------------\n";
cout<<"----------- ---------------\n";
cout<<"----------- CEO: ---------------\n";
cout<<"---- Email:[email protected] -----\n";
cout<<"----------- QQ:361198638 ---------------\n";
cout<<"--------------------------------------------\n";
cout<<"\a\n";
cout<<"欢迎进入石头剪子布小游戏世界!\n";
cout<<"按任意键开始拿拆没..."<<endl;
getch();
do
{
int cho;
cout<<"消纳\n";
cout<<"//////////////新一局/////////////////\n";
cout<<"1.出剪子\n";
cout<<"2.出石头\n";
cout<<"3.出布\n";
cout<<"*************************************\n";
cout<<"请选择";
cin>>cho;
if(cho<1||cho>3)
{
cout<<"请输入1-3的数字!\n";
continue;
}
int good;
good=main1(temp);
switch (good)
{
case 0:
cout<<"对方出了剪子\n";
if(cho==1)
{
cout<<"势均力敌\n";
ping++;
}
else if(cho==2)
{
cout<<"您赢了御埋!\n";
ying++;
}
else if(cho==3)
{
cout<<"您输了!\n";
shu++;
}
break;
case 1:
cout<<"对方出了石头\n";
if(cho==1){
cout<<"您输了\n";
shu++;}
else if(cho==2)
{
cout<<"势均力敌\n";
ping++;
}
else if(cho==3)
{
cout<<"您赢了!\n";
ying++;
}
break;
case 2:
cout<<"对方出了布\n";
if(cho==1)
{
cout<<"您赢了!\n";
ying++;
}
else if(cho==2)
{
cout<<"您输了!\n";
shu++;
}
else if(cho==3)
{
cout<<"势均力敌\n";
ping++;
}
}
cout<<"战况:赢"<<ying<<"次;输:"<<shu<<"次;平:"<<ping<<"次.\a\n";
cout<<"_____________________________________\n";
}
while(1);
cout<<temp<<"\n";
return 1;
}
*************************************
G. c语言程序设计实例
// 电话本Dlg.cpp : 实现文件
//
#include stdafx.h
#include 电话本.h
#include 电话本Dlg.h
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// C电话本Dlg 对话框
C电话本Dlg::C电话本Dlg(CWnd* pParent /*=NULL*/)
: CDialog(C电话本Dlg::IDD, pParent)
{
m_hIcon = AfxGetApp()-LoadIcon(IDR_MAINFRAME);
}
void C电话本Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(C电话本Dlg, CDialog)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_EN_CHANGE(IDC_EDIT1, C电话本Dlg::OnName)
ON_EN_CHANGE(IDC_EDIT2, C电话本Dlg::OnPhoto)
ON_EN_CHANGE(IDC_EDIT3, C电话本Dlg::OnAddress)
ON_EN_CHANGE(IDC_EDIT4, C电话本Dlg::OnShow)
ON_BN_CLICKED(IDC_BUTTON1, C电话本Dlg::OnFill)
ON_BN_CLICKED(IDC_BUTTON2, C电话本Dlg::OnInsert)
ON_BN_CLICKED(IDC_BUTTON3, C电话本Dlg::OnFind)
ON_BN_CLICKED(IDC_BUTTON4, C电话本Dlg::OnDelete)
ON_BN_CLICKED(IDC_BUTTON5, C电话本Dlg::OnEdit)
ON_BN_CLICKED(IDC_BUTTON7, C电话本Dlg::OnSave)
END_MESSAGE_MAP()
// C电话本Dlg 消息处理程序
BOOL C电话本Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
// 执行此操作
SetIcon(m_hIcon, TRUE); // 设置大图标
SetIcon(m_hIcon, FALSE); // 设置小图标
// TODO: 在此添加额外的初始化代码
ifstream InFile(Wab.fsd,ios::in);
listWabList::iterator ItWab;
char Tmp1[8],Tmp2[16],Tmp3[32];
Wab.clear();
while(InFile Tmp1 Tmp2 Tmp3)
{
OutWab.Name=Tmp1;
OutWab.Photo=Tmp2;
OutWab.Address=Tmp3;
Wab.push_front(OutWab);
}
C电话本Dlg::OnFill();
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
}
// 如果向对话框添加最小化按钮,则需要下面的代码
// 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
// 这将由框架自动完成。
void C电话本Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // 用于绘制的设备上下文
SendMessage(WM_ICONERASEBKGND, reinterpret_castWPARAM(dc.GetSafeHdc()), 0);
// 使图标在工作矩形中居中
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(rect);
int x = (rect.Width() - cxIcon 1) / 2;
int y = (rect.Height() - cyIcon 1) / 2;
// 绘制图标
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
//当用户拖动最小化窗口时系统调用此函数取得光标显示。
//
HCURSOR C电话本Dlg::OnQueryDragIcon()
{
return static_castHCURSOR(m_hIcon);
}
void C电话本Dlg::OnName()
{
CEdit *pMaxLen=(CEdit*)GetDlgItem(IDC_EDIT1);
pMaxLen-SetLimitText(6);
GetDlgItemText(IDC_EDIT1,InWab.Name);
}
void C电话本Dlg::OnPhoto()
{
CEdit *pMaxLen=(CEdit*)GetDlgItem(IDC_EDIT2);
pMaxLen-SetLimitText(11);
GetDlgItemText(IDC_EDIT2,InWab.Photo);
}
void C电话本Dlg::OnAddress()
{
CEdit *pMaxLen=(CEdit*)GetDlgItem(IDC_EDIT3);
pMaxLen-SetLimitText(30);
GetDlgItemText(IDC_EDIT3,InWab.Address);
}
void C电话本Dlg::OnShow()
{
// TODO: 如果该控件是 RICHEDIT 控件,则它将不会
// 发送该通知,除非重写 CDialog::OnInitDialog()
// 函数并调用 CRichEditCtrl().SetEventMask(),
// 同时将 ENM_CHANGE 标志“或”运算到掩码中。
// TODO: 在此添加控件通知处理程序代码
}
void C电话本Dlg::OnFill()
{
CString OutAll,OutTemp,Space,Enter;
Space=_T( );
Enter=_T(\r\n);
listWabList::iterator ItWab;
for(ItWab=Wab.begin();ItWab!=Wab.end();ItWab )
{
OutWab=*ItWab;
OutTemp=OutWab.Name Space OutWab.Photo Space OutWab.Address;
OutAll=OutAll OutTemp Enter;
}
SetDlgItemText(IDC_EDIT4,OutAll);
}
void C电话本Dlg::OnInsert()
{
Wab.push_front(InWab);
C电话本Dlg::OnFill();
}
void C电话本Dlg::OnFind()
{
CString OutAll,OutTemp,Space,Enter;
Space=_T( );
Enter=_T(\r\n);
listWabList::iterator ItWab;
for(ItWab=Wab.begin();ItWab!=Wab.end();ItWab )
{
if(ItWab-Name==InWab.Name)
{
OutTemp=ItWab-Name Space ItWab-Photo Space ItWab-Address;
OutAll=OutAll OutTemp Enter;
}
}
SetDlgItemText(IDC_EDIT4,OutAll);
}
void C电话本Dlg::OnDelete()
{
CString OutAll,OutTemp,Space,Enter;
Space=_T( );
Enter=_T(\r\n);
listWabList::iterator ItWab;
for(ItWab=Wab.begin();ItWab!=Wab.end();ItWab )
{
if(ItWab-Name==InWab.Name)
{
OutTemp=ItWab-Name Space ItWab-Photo Space ItWab-Address;
OutAll=OutAll OutTemp Enter;
break;
}
}
SetDlgItemText(IDC_EDIT4,OutAll);
if(ItWab!=Wab.end()) Wab.erase(ItWab);
}
void C电话本Dlg::OnEdit()
{
CString OutAll,OutTemp,Space,Enter;
Space=_T( );
Enter=_T(\r\n);
listWabList::iterator ItWab;
for(ItWab=Wab.begin();ItWab!=Wab.end();ItWab )
{
if(ItWab-Name==InWab.Name)
{
OutTemp=ItWab-Name Space ItWab-Photo Space ItWab-Address;
OutAll=OutAll OutTemp Enter;
break;
}
}
SetDlgItemText(IDC_EDIT4,OutAll);
if(ItWab!=Wab.end())
{
Wab.erase(ItWab);
Wab.push_front(InWab);
}
}
void C电话本Dlg::OnSave()
{
CString Tmp1,Tmp2,Tmp3;
ofstream OutFile(Wab.fsd,ios::out);
listWabList::iterator ItWab;
for(ItWab=Wab.begin();ItWab!=Wab.end();ItWab )
{
Tmp1=ItWab-Name;
Tmp2=ItWab-Photo;
Tmp3=ItWab-Address;
OutFile Tmp1 ' ' Tmp2 ' ' Tmp3 endl;
}
}
只是个用C语言编写的电话本程序 很有实用意义
H. C语言程序设计:通讯录程序设计
#include "stdlib.h"
#include "string.h"
#include "conio.h"
#include "stdio.h"
#include "dos.h"
FILE *fp;
int i; //i是全局变量 可代替length
struct address
{ char postnum[10];
char a[40]; //家庭地址
};
struct birthday
{ int year;
int month;
int day;
};
struct ffriend
{ int num; //序号
char name[20];
char sex;
char telephone[13];
struct birthday birthday;
struct address address;
}
friends[50];
void Load()
{
int j;
long k;
fp=fopen("friend.txt","a+"); //打开文件friend.txt
if(fp!=NULL)
{
for(i=1;i<50;i++)
{
j=fgetc(fp);
if(j==EOF) //判断是否到了文件尾
return;
k=i-1;
fseek(fp,k*sizeof(struct ffriend),SEEK_SET);
fread(&friends[i],sizeof(struct ffriend),1,fp); //从文件中读取一条记录
}
}
else
{
fp=fopen("friend.txt","w");
i=1;
}
}
void Show(int j)
{
// friends[j].num=i;
printf("\n\n\t编号-Nnumber: %3d",friends[j].num);
printf("\n\t姓名-Name:%-20s",friends[j].name);
printf("\n\t性别-Sex:%c",friends[j].sex);
printf("\n\t联系电话-Telephone:%-13s",friends[j].telephone);
printf("\n\t出生日期-Birthday:%4d-%2d-%3d",friends[j].birthday.year,friends[j].birthday.month,friends[j].birthday.day);
printf("\n\t邮编-Postnum:%-10s",friends[j].address.postnum);
printf("\n\t通信地址-address:%-40s",friends[j].address.a);
}
void Append(int j)
{
fflush(stdin); //区内清除文件缓冲区,文件以写方式打开时将缓冲容写入文件
//stdin是一个标准FILE*(文件型指针)指向通常是用键盘的输入的输入流
friends[j].num=j;
printf("\n\t\t\t序号-Number:%d",j);
printf("\n\t\t\t姓名-Name:");
scanf("%s",friends[j].name);
fflush(stdin); //为什么没有fflush(stdin); 的效果会自动跳过呢?
printf("\t\t\t性别-Sex(m/w):"); //为什么输入汉字男女也会自动跳过联系电话呢
scanf("%c",&friends[j].sex);
printf("\t\t\t联系电话-telephone:");
scanf("%s",friends[j].telephone);
printf("\t出生日期-birthday");
printf("\n\t\t\t年份-year:");
scanf("%d",&friends[j].birthday.year);
printf("\t\t\t月份-month:");
scanf("%d",&friends[j].birthday.month);
printf("\t\t\t日-day:");
scanf("%d",&friends[j].birthday.day);
printf("\t\t\t邮编-Postnumber:");
scanf("%s",friends[j].address.postnum);
printf("\t\t\t通信地址-Address:");
scanf("%s",friends[j].address.a);
getchar();
}
void Delete()
{
int k;
printf("\n\tDelete 序号-Number:");
scanf("%d",&k);
if(k<=i)
{
for(int j=k;j<i+1;j++) /*插入位置后的元素顺序后移*/
{
strcpy(friends[j].name,friends[j+1].name); /*交换元素内容*/
friends[j].sex=friends[j+1].sex;
strcpy(friends[j].telephone,friends[j+1].telephone);
friends[j].birthday.year=friends[j+1].birthday.year;
friends[j].birthday.month=friends[j+1].birthday.month;
friends[j].birthday.day=friends[j+1].birthday.day;
strcpy(friends[j].address.postnum,friends[j+1].address.postnum);
strcpy(friends[j].address.a,friends[j+1].address.a);
}
i--;
}
else
{
printf("输入的序号太大!");
}
}
void Modify(int j)
{
Append(j);
}
void Save()
{
int j;
fp=fopen("friend.txt","w");
for(j=1;j<=i;j++)
{
fwrite(&friends[j],sizeof(struct ffriend),1,fp);
}
fclose(fp);
}
void main()
{
int j;
char grade;
char searchname[10];
Load();
i--;
do
{
printf("\t\t\t\t简易通讯录\n\n");
printf("功能选择(Function choose)\n");
printf("\1A.读取(Read)\n");
printf("\2B.增添(Append)\n");
printf("\6C.插入(Insert)\n");
printf("\5D.删除(Delete)\n");
printf("\5E.查询(Search)\n");
printf("\6F.修改(Modify)\n");
printf("\2G.保存(Save)\n");
printf("\1H.退出(Quit)\n");
printf("请选择(Choice)\n注:输入A~H的大写字母\n");
scanf("%c",&grade);
switch(grade)
//加个大写和小写 都可以啊
{
case 'A': j=1; //显示功能
while(getchar()!=0x1b&&j<=i) //增添按Esc键退出
{
Show(j++);
printf("\n请按回车键继续!");
}
if(j-1<1)
{
printf("\n\t空文档,无任何记录-Empty Note\n");
printf("\n请按回车键继续!");
getchar();
}
printf("\n\t\t\t\t\t\t\t此次操作结束");
printf("\n\t------------------------------------------------------------\t\t\n");
break;
case 'B': //增加功能
while(i<=50) //增加按ESC键退出的功能
{
i++;
Append(i);
printf("\t是否继续增加?y/n");
//修改 加上else if 其他就跳出或强制打印出出错
char a=getchar();
if(a=='n'||a=='N')
break;
}
if(i==51)
printf("\n\t文档已满,无法增加记录-note full");
printf("\n\t\t\t\t\t\t\t此次操作结束");
printf("\n\t------------------------------------------------------------\t\t\n");
getchar();
break;
case 'C':
int k;
printf("\n\t输入要插入的位置:");
scanf("%d",&k);
j=i+1;
friends[j].num=j;
for(j;j>k;j--) //插入功能
{
strcpy(friends[j].name,friends[j-1].name); //数据后移
friends[j].sex=friends[j-1].sex;
strcpy(friends[j].telephone,friends[j-1].telephone);
friends[j].birthday.year=friends[j-1].birthday.year;
friends[j].birthday.month=friends[j-1].birthday.month;
friends[j].birthday.day=friends[j-1].birthday.day;
strcpy(friends[j].address.postnum,friends[j-1].address.postnum);
strcpy(friends[j].address.a,friends[j-1].address.a);
}
Append(k);
i++;
printf("\n\t\t\t\t\t\t\t此次操作结束");
printf("\n\t------------------------------------------------------------\t\t\n");
break;
case 'D': //删除功能 //增添随意删除多条记录的功能
Delete();
if(i<1)
printf("\n没有记录-No records\n");
printf("\n请按回车键继续!");
getchar();
getchar();
printf("\n\t\t\t\t\t\t\t此次操作结束");
printf("\n\t------------------------------------------------------------\t\t\n");
break;
case 'E': //查询功能
printf("\n\t请输入要查询记录的相关姓名:"); //增添查询按列号的
scanf("%s",searchname);
for(j=1;j<=i;j++)
{
if(strcmp(searchname,friends[j].name)==0) //比较字符串
{
Show(j);
break;
}
}
if(i<1)
{
printf("\n 没有您所查询的记录-No records");
printf("\n 请按回车键继续!");
getchar();
}
printf("\n\t\t\t\t\t\t\t此次操作结束");
printf("\n\t------------------------------------------------------------\t\t\n");
getchar();
break;
case 'F': //修改功能 / /增添按序列号查询
printf("\n\t请输入要修改记录的相关姓名:");
gets(searchname);
scanf("%s",searchname);
for(j=1;j<=i;j++)
{
if(strcmp(searchname,friends[j].name)==0) //比较字符串
{
Modify(j);
// getchar(); //加个输出确定修改吗
}
}
if(i<1) //修改功能
{ printf("\n 没有您所要修改的记录-No records");
printf("\n 请按回车键继续!");
getchar();
getchar();
}
printf("\n\t\t\t\t\t\t\t此次操作结束");
printf("\n\t------------------------------------------------------------\t\t\n");
break;
case 'G':
Save(); //存盘功能
getchar();
printf("\n\t\t\t\t\t\t\t此次操作结束");
printf("\n\t------------------------------------------------------------\t\t\n");
break;
case 'H': //退出功能
char x;
printf("是否保存?yes/no\n");
scanf("%s",&x);
//getchar();
// getchar();
if(x=='y')
{
Save();
exit(0);
}
else
exit(0);
default:
printf("\n\t输入有误,请输入正确的序列号!");
printf("\n请按回车键继续!");
getchar();
printf("\n\t\t\t\t\t\t\t此次操作结束");
printf("\n\t------------------------------------------------------------\t\t\n");
}
}while(1);
}
I. C语言 程序设计
#include <stdio.h> //3、给数据加密程序。
#include <math.h>
int encrypt(int a,int b,int c,int d); //加密函数
int deciphering(int a,int b,int c,int d); //解密函数
main()
{
int number,k;
int g,s,b,q;
printf("please enter a number(四位数):");
scanf("%d",&number);
printf("---------------------------------\n"); //菜单
printf("-------------菜单选项------------\n");
printf("---------------------------------\n");
printf("1.对输入的四位数进行加密操作。\n");
printf("2.对输入的四位数进行解密操作。\n");
printf("3.退出程序。\n");
printf("---------------------------------\n");
while(k!=3) //循环选择操作
{
printf("please enter your chance:");
scanf("%d",&k);
g=number%10;
s=number/10%10;
b=number/100%10;
q=number/1000;
switch(k)
{
case 1: //加密选项
{
encrypt(g,s,b,q);
printf("加密后的数字为:%d\n",encrypt(g,s,b,q));
}
break;
case 2: //解密选项
{
deciphering(g,s,b,q);
printf("解密后的数字为:%d\n",deciphering(g,s,b,q));
}
break;
case 3: //退出选项
{
printf("close the code!\n");
}
break;
default:
{
}
break;
}
}
}
int encrypt(int a,int b,int c,int d) //加密函数
{
int encryptnumber=0;
int temp1,temp2;
if(a+5>=10) //闷神判断是否超过十,此处可以简化为函数,不过我没做
{
a=abs(a+5-10);
}
else
{
a=a+5;
}
if(b+5>=10)
{
b=abs(b+5-10);
}
else
{
b=b+5;
}
if(c+5>=10)
{
c=abs(c+5-10);
}
else
{
c=c+5;
}
if(d+5>模枝=10)
{
d=abs(d+5-10);
}
else
{
d=d+5;
}
temp1=a;
a=d;
d=temp1;
temp2=b;
b=c;
c=temp2;
encryptnumber=d*1000+c*100+b*10+a;
//printf("加密后的数字为:%d\n",encryptnumber);
return encryptnumber;
}
int deciphering(int a,int b,int c,int d) //解密函数
{
int encrypt(int a,int b,int c,int d); //函数嵌套
int decipheringnumber=0;
int encryptnum=encrypt(a,b,c,d); //取蚂码亏得加密函数的结果
int temp1,temp2;
int gg,ss,bb,qq;
gg=encryptnum%10;
ss=encryptnum/10%10;
bb=encryptnum/100%10;
qq=encryptnum/1000;
temp1=gg;
gg=qq;
qq=temp1;
temp2=bb;
bb=ss;
ss=temp2;
if(gg-5<=0) //判断是否超过十,此处可以简化为函数,不过我没做
{
gg=abs(gg-5+10);
}
else
{
gg=gg-5;
}
if(ss-5<=0)
{
ss=abs(ss-5+10);
}
else
{
ss=ss-5;
}
if(bb-5<=0)
{
bb=abs(bb-5+10);
}
else
{
bb=bb-5;
}
if(qq-5<=0)
{
qq=abs(qq-5+10);
}
else
{
qq=qq-5;
}
decipheringnumber=qq*1000+bb*100+ss*10+gg;
return decipheringnumber;
}
J. 什么是c语言程序设计
C语言是一门通用计算机编程语言,应用广泛。C语言的设计目标是提供一种能以简易的方式编译、处理低级存储器、产生少量的机器码以及不需要任何运行环境支持便能运行的编程语言。
尽管C语言提供了许多低级处理的功能,但仍然保持着良好跨平台的特性,以一个标准规格写出的C语言程序可在许多电脑平台上进行编译,甚至包含一些嵌入式处理器(单片机或称MCU)以及超级电脑等作业平台。
二十世纪八十年代,为了避免各开发厂商用的C语言语法产生差异,由美国国家标准局为C语言订定了一套完整的国际标准语法,称为ANSI C,作为C语言最初的标准。
c语言程序设计 就是用c语言的功能函数开发的程序。