❶ c语言程序设计 (学生选修课程设计)
这是我做的,你看是否满意?可能有点大,但也没办法呀,你的题目也比较大,呵呵!所以,如果满意,多给我追加点分!
#include
"stdio.h"
#include
"stdlib.h"
#include
"string.h"
typedef
struct
course
{
char
number[15],name[25];
int
kind,time,lessontime,practicetime,credit,term;
}type;
FILE
*fp1;
void
overview();
//浏览函数,负责浏览整个课程信息
void
seek();
//查询函数,负责查询课程信息
void
choose_course();//选课函数,负责让用户选课
void
out(type
temp);
void
input();
int
main()
{
int
n,i;
if((fp1=fopen("course_information.txt","wb"))==NULL)
{printf("创建文件失败!\n");exit(0);}
printf("请输入要存储的课程数目:\n");
scanf("%d",&n);
printf("开始创建文件,请输入课程信息:\n\n");
for(i=0;i<n;i++)
{
printf("请输入第%d门课程的信息:\n",i+1);
input();
printf("\n");
}
printf("如想浏览整个课程信息,请输入1;如想查询课程信息,请输入2;
如想进行选课,请输入3;如想结束选修课系统,请输入0!\n");
while((scanf("%d",&n))!=EOF)
{
if(n==1)
overview();
if(n==2)
seek();
if(n==3)
choose_course();
if(n==0)
exit(0);
printf("\n\n如想继续操作,只要按规则输入你要进行的操作即可!\n规则:如想浏览整个课程信息,请输入1;如想查询课程信息,请输入2;如想进行选课,请输入3!\n");
}
printf("欢迎您使用此程序进行选课,谢谢!\n");
fclose(fp1);
return
0;
}
void
input()
{
course
c_a;
printf("请输入课程编码:
");
scanf("%s",c_a.number);
printf("请输入课程名:
");
scanf("%s",c_a.name);
printf("请输入课程性质:限选课,请输入1;选修课,请输入2;必修课,请输入3!
");
scanf("%d",&c_a.name);
printf("请输入课程总学时:
");
scanf("%d",&c_a.time);
printf("请输入课程授课时间:
");
scanf("%d",&c_a.lessontime);
printf("请输入课程实验或实践时间:
");
scanf("%d",&c_a.practicetime);
printf("请输入课程学分:
");
scanf("%d",&c_a.credit);
printf("请输入课程所在的学期,比如第二学期,就输入2即可。");
scanf("%d",&c_a.term);
fwrite(&c_a,sizeof(struct
course),1,fp1);//将一个结构体元素写入文件中
}
void
out(type
temp)
{
printf("课程代码:
%s\n课程名:
%s\n",temp.number,temp.name);
printf("课程名:
%s\n",temp.name);
if(temp.kind==1)
printf("课程性质:
Limited
optional
course\n");
else
if(temp.kind==2)
printf("课程性质:
Optional
course\n");
else
if(temp.kind==3)
printf("课程性质:
Required
Courses\n");
else
printf("该编码系统不认识,即无对应的课程性质存在!\n");
printf("课程总学时:
%d\n课程授课学时:
%d\n实验或上机学时:
%d\n学分:
%d\n课程开课学期:
%d\n\n",temp.time,temp.lessontime,temp.practicetime,temp.credit,temp.term);
}
void
overview()
{
rewind(fp1);
course
temp;
printf("整个课程信息如下:\n");
while((fread(&temp,sizeof(type),1,fp1))!=0)
out(temp);
}
void
seek()
{
int
judge,credit=0,kind=0;
char
a='N';
course
temp;
printf("如想按学分查询,请输入1;如想按课程性质,请输入2:\n");
scanf("%d",&judge);
rewind(fp1);
//将文件指针位置置为开头
if(judge==1)
{
printf("请输入要查询的学分:\n");
scanf("%d",&credit);
while((fread(&temp,sizeof(type),1,fp1))!=0)
if(credit==temp.credit)
out(temp);
}
else
if(judge==2)
{
printf("请输入你要查找课程的性质(限选课,请输入1;选修课,请输入2;必修课,请输入3):");
scanf("%d",&kind);
while((fread(&temp,sizeof(type),1,fp1))!=0)
if(temp.kind==kind)
out(temp);
}
else
printf("不好意思,无此类查询!\n");
}
void
choose_course()
{
rewind(fp1);
course
temp;
int
judge=1,n=0,time=0,credit=0;
char
choose[20][20];
r1:
printf("请开始填写课程编号进行选课:\n");
while(judge==1)
{
printf("请输入你所选课程的标号:
");
scanf("%s",choose[n]);
n++;
printf("如想继续选课,请输入1;如想提交,请输入0!\n");
scanf("%d",&judge);
}
while((fread(&temp,sizeof(type),1,fp1))!=0)
{
for(int
i=0;i<n;i++)
if(strcmp(temp.number,choose[i])==0)
{time=time+temp.time;credit=temp.credit;break;}
}
if(time<270||credit<40)
goto
r1;
printf("你所选的课为:\n");
while((fread(&temp,sizeof(type),1,fp1))!=0)
{
for(int
i=0;i<n;i++)
if(strcmp(temp.number,choose[i])==0)
{out(temp);break;}
}
}
❷ C语言程序设计李含光版和宋丽华版有什么区别
就拿第四版和第三版作对比,区别如下:
1、指代不同
(1)C程序设计谭浩强版本的第四版:这是清华大学出版社2010年出版的一本书,作者是谭浩强。
(2)C程序设计谭浩强版本的第三版:被普遍认为是学习C语言的一本好教科书,并且被全国大多数大学所选择。
2、影响不同
(1)C程序设计谭浩强版本的第四版:本书被大多数大学用作C语言学习的教科书,且纠正了第三版中的不足。
(2)C程序设计谭浩强版本的第三版:获原电子工业部优秀教科书一等奖,大学出版社畅销书特等奖,全国高等院校计算机基础教育研究会优秀教材一等奖。
3、特点不同
(1)C程序设计谭浩强版本的第四版:内容先进,体系合理,概念清晰,说明详尽,步骤少,分散困难点,实例丰富,通俗易懂,文字通俗易懂,是初学者学习C程序设计理想的教材,可以用作大学所有专业的正式教材。
(2)C程序设计谭浩强版本的第三版:已发行超过700万册,创下了类似书籍的全国记录,并且是学习C语言的主流书籍。
❸ C语言程序设计
int chengji;
char degree;
scanf("%d",&chengji);//获取成绩
if(chengji >84) degree ='A';
else if(chengji>69) degree ='B';
else if(chengji>59) degree ='C';
else degree ='D';
printf("%c",degree);
///////////////////////////////////////
scanf("%c",degree);//获取等级
if(degree == 'A') printf(">=85");
else if(degree == 'B') printf("70-84");
else if(degree == 'C')printf("60-69");
else if(degree =='D') printf("<60");
else printf("the degree you input is not exist!!");
❹ 《C语言程序设计》课程设计
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#define BUFFERSIZE 1024
#define MAXACCOUNT 1000
typedef struct BankAccount
{
int account;
int key;
char name[32];
float balance;
}BANKACCOUNT;
BANKACCOUNT accountCollection[MAXACCOUNT];
int curAccount = 0;
void InsertAccount(FILE *fp)
{
BANKACCOUNT newaccount;
printf("please input the account information\n");
printf(">>account num:");
scanf("%d",&(newaccount.account));
printf(">>key:");
scanf("%d",&(newaccount.key));
printf(">>name:");
scanf("%s",newaccount.name);
printf(">>balance:");
scanf("%f",&(newaccount.balance));
fseek(fp,0L,SEEK_END);
fprintf(fp,"%d %d %s %.2f\n",newaccount.account,newaccount.key,newaccount.name,newaccount.balance);
}
void GetAccount(FILE *fp)
{
int accountnum;
int key;
char name[32];
float balance;
int i =0,j;
char buffer[BUFFERSIZE];
int len;
curAccount = 0;
fseek(fp,0,SEEK_SET);
while(!feof(fp)) /* 因为feof()最后会读2遍,所以最后curAccount多加了1 */
{
fscanf(fp,"%d %d %s %f",&accountnum,&key,name,&balance);
accountCollection[curAccount].account = accountnum;
accountCollection[curAccount].key = key;
strcpy(accountCollection[curAccount].name ,name);
accountCollection[curAccount].balance = balance;
curAccount++;
}
}
void ListAccount(FILE *fp)
{
int i =0;
printf("There is %d accounts at all:\n",curAccount-1);/* curAccount减去多加的1 */
for(i = 0;i< curAccount-1;i++)
{
printf("ACCOUNT[%d]:\n",i+1);
printf("account:%d\n",accountCollection[i].account);
printf("name:%s\n",accountCollection[i].name);
printf("balance:%.2f\n",accountCollection[i].balance);
}
}
int SearchAccount(FILE *fp,int accountnum)
{
int i =0;
for(i = 0;i< curAccount-1;i++)
{
if(accountCollection[i].account == accountnum)
{
printf("ACCOUNT[%d]:\n",i+1);
printf("account:%d\n",accountCollection[i].account);
printf("name:%s\n",accountCollection[i].name);
printf("balance:%.2f\n",accountCollection[i].balance);
return 1;
}
}
return 0;
}
void DelAccount(FILE *fp,int accountnum)
{
int i;
if(SearchAccount(fp,accountnum)==0)
printf("Can't find the account\n");
else
{
for(i = 0;i<curAccount-1;i++)
{
if(accountCollection[i].account != accountnum)
fprintf(fp,"%d %d %s %.2f\n",accountCollection[i].account,accountCollection[i].key,accountCollection[i].name,accountCollection[i].balance);
}
printf("delete successfully!\n");
}
}
int main()
{
FILE *fp;
int accountnum;
int i;
do{
system("cls"); //清屏
puts("********************************************");
puts("* You can choose : *");
puts("* 1 : Insert a new Account *");
puts("* 2 : List all Accounts *");
puts("* 3 : Find a Account *");
puts("* 4 : Delete a Account *");
puts("* 5 : quit *");
puts("********************************************");
printf("Please input your choice:");
scanf("%d",&i);
system("cls"); //清屏
switch(i)
{
case 1:
if(!(fp = fopen("account.txt","a+")))
{
printf("can't open the file account.txt\n");
exit(0);
}
InsertAccount( fp);
printf("press any key to continue.....\n");
getch();
fclose(fp);
break;
case 2:
if(!(fp = fopen("account.txt","r")))
{
printf("can't open the file account.txt\n");
exit(0);
}
GetAccount(fp);
ListAccount(fp);
fclose(fp);
printf("press any key to continue.....\n");
getch();
break;
case 3:
printf("please input the account num:\n");
scanf("%d",&accountnum);
if(!(fp = fopen("account.txt","r")))
{
printf("can't open the file account.txt\n");
exit(0);
}
GetAccount(fp);
if(!SearchAccount(fp,accountnum))
printf("There is not the account:%d\n",accountnum);
fclose(fp);
printf("press any key to continue.....\n");
getch();
break;
case 4:
printf("please input the account num:\n");
scanf("%d",&accountnum);
if(!(fp = fopen("account.txt","r")))
{
printf("can't open the file account.txt\n");
exit(0);
}
GetAccount(fp);
fclose(fp);
if(!(fp = fopen("account.txt","w+")))
{
printf("can't open the file account.txt\n");
exit(0);
}
DelAccount(fp,accountnum);
fclose(fp);
printf("press any key to continue.....\n");
getch();
break;
default:
break;
}
}while(i != 5);
return 0;
}
账户数据文件名已经设定为account.txt,这个文件要和上面这个程序放在同一个文件夹下面,不然就得用绝对路径(比如"d:\\book\\account.txt"),account内容可以用记事本打开自己改动,然后运行程序后就可以在程序中添加或删除
❺ c语言程序设计
#include<stdio.h>
struct stu{
char name[12];
int num1;
}b[5],k;
void main(){
int i,j;
printf("请依次输入学生姓名及成绩\n");
for(i=0;i<5;i++)
scanf("%s%d",&b[i].name,&b[i].num1);
for(i=0;i<5;i++){
for(j=0;j<4-i;j++)
if(b[j].num1<b[j+1].num1){
k=b[j];
b[j]=b[j+1];
b[j+1]=k;
}
}
printf("按成绩高低排序输出\n");
printf("名次 姓名 成绩\n");
for(i=0;i<5;i++){
printf("%-5d%-10s%-6d",i+1,b[i].name,b[i].num1);
printf("\n");
}
}
默认的人数为5.
❻ c语言程序设计例题
题目1
#include "stdio.h"
void main(void)
{
int n=5,m=10,i=1;
long sum=1;
for(;i<=n;i++)
{
sum*=i;
}
printf("\n5!=%d",sum);
for(i=1;i<=10;i++)
{
sum*=i;
}
printf("\n10!=%d",sum);
}
题目2
#include "stdio.h"
#include "string.h"
struct Student
{
char s_Name[25];
long n_Code;
int n_English;
int n_Math;
int n_Computer;
}student_1,student_2;
void main(void)
{
printf("\nStudent1:\nName:");
scanf("%s",&student_1.s_Name);
printf("StudentNum:");
scanf("%d",&student_1.n_Code);
printf("English Score:");
scanf("%d",&student_1.n_English);
printf("Math Score:");
scanf("%d",&student_1.n_Math);
printf("Computer Score:");
scanf("%d",&student_1.n_Computer);
printf("\nStudent2:\nName:");
scanf("%s",&student_2.s_Name);
printf("StudentNum:");
scanf("%d",&student_2.n_Code);
printf("English Score:");
scanf("%d",&student_2.n_English);
printf("Math Score:");
scanf("%d",&student_2.n_Math);
printf("Computer Score:");
scanf("%d",&student_2.n_Computer);
printf("\nStudent1:\nName:%s\nStudent Number:%d\nEnglish Score:%d\nMath Score:%d\nComputer Score:%d\n",student_1.s_Name,student_1.n_Code,student_1.n_English,student_1.n_Math,student_1.n_Computer);
printf("\nStudent2:\nName:%s\nStudent Number:%d\nEnglish Score:%d\nMath Score:%d\nComputer Score:%d\n",student_2.s_Name,student_2.n_Code,student_2.n_English,student_2.n_Math,student_2.n_Computer);
}
❼ 《C语言程序设计》第17章在线测试
1、D 因为#define C(x) ((x)*(x))宏中需要使用完备的括号才不会有引用错误
2、D 认真区分char a[]和char *p的区别,a是数组的首地址,也是指针,但是p仅仅是指向一个字符串的首地址的指针,虽然也是指针,但是你并不知道p指针具体在什么代码段的什么位置,从而p+=2的位置你也无法确定。
3、C extern本来就是外部的意思嘛
4、A 仅仅在主函数中有效,这是对的。
5、B 局部变量优先,给你举个例子:
int a=1;
int main()
{
int a=2;
cout<<a;
return 0;
}
就是类似这样的例子,你在main函数外定义了一个全局变量a,在main内部又定义了一个变量名也是a的局部变量,那么你在main中用cout输出的时候就是输出了局部变量a的值,要输出全局变量a的值时则要使用::a,实际上是局部变量将全局变量屏蔽了,可以看做局部变量的优先于全局变量
/**********************************************************************************/
第二题1、ABC
2、ABD
3、CD
4、AB
5 、AD
/**********************************************************************************/
第三题
正确
错误,可改为int *p=&x
错误,不是指向结构体的指针,不可以用->
正确,因为数组名那可是一个指针,是数组的首地址
正确 当然可以递归了,网上多的是那种递归的小程序
如果有什么不清楚,咱们可以后续交流哦@—@