c语言程序设计理论方法与实践21世纪高等学校规划教材计算机科学与技术是c吗

Python023

c语言程序设计理论方法与实践21世纪高等学校规划教材计算机科学与技术是c吗,第1张

是C语言,不是C++

《21世纪高等学校规划教材·计算机科学与技术·山东省精品课程配套教材:C语言程序设计:理论、方法与实践》面向程序设计初学者编写,以“学习基本理论、掌握基本方法、培养基本实践能力”为编写指导思想,突出C语言课程的应用性、实践性特点,综合运用案例教学、任务驱动、启发式教学等多种教学方法,对C语言程序设计的语言知识和程序设计的方法过程进行系统介绍,特别适合将C语言程序设计作为第一门程序设计课程的高校学生学习使用。

全书共有9章,分别为程序设计概述、简单程序设计、分支结构程序设计、循环结构程序设计、数组程序设计、函数程序设计、指针程序设计、结构体程序设计和文件程序设计。每章均设有实验指导,分为基础实验和综合实验两部分,与理论教学内容密切衔接,相辅相成。《21世纪高等学校规划教材·计算机科学与技术·山东省精品课程配套教材:C语言程序设计:理论、方法与实践》配有教学课件、例题程序源代码和试题库等丰富的教学资源。

《21世纪高等学校规划教材·计算机科学与技术·山东省精品课程配套教材:C语言程序设计:理论、方法与实践》适合作为高等院校C语言程序设计等相关课程的教材,也可用作程序设计人员及程序设计爱好者的自学参考书。

具体要求如下:

1、 采取模块化方式进行程序设计,要求程序的功能设计、数据结构设计及整体结构设计合理。学生也可根据自己对题目的理解增加新的功能模块(视情况可另外加分)。

2、 系统以菜单界面方式(至少采用文本菜单界面,如能采用图形菜单界面更好)工作,运行界面友好,演示程序以用户和计算机的对话方式进行。

3、 程序算法说明清晰,理论分析与计算正确,运行情况良好,实验测试数据无误,容错性强(能对错误输入进行判断控制)。

4、 编程风格良好(包括缩进、空行、适当注释、变量名和函数名见名知意,程序容易阅读等);

5、 写出规范的课程设计报告,具体要求见相关说明文档。

某学校有实验机房n个,每个机房管理信息包括:(房间号、机房类型、可容纳学生人数、实验员、是否在使用)。

例如:

房间号 机房类型 可容纳学生人数 实验员 是否在使用

01网络实验 40 张是

02软件实验 90 林否

03系统结构实验 45 丁否

04软件实验 120 马否

功能要求:

(1)录入实验室信息,可增加、删除实验机房信息。如果机房正在使用,不能删除。

(2)浏览所有机房信息,可显示出所有实验室情况

(3)如果有班级申请某类型实验室,若有该类型的空机房,且容量大于班级学生数,则分配该机房,更新管理信息。

(4)可以根据房间号或机房类型查询所有机房信息

收先建立一个TXT文件,储存以下资料:姓名学号 语文 数学 英语

张明明 01 6778 82

李成友 02 7891 88

张辉灿 03 6882 56

王露04 5645 77陈东明 05 6738 4---------------------------------------------------------------------------代码如下,本人亲自写的,不会有什么错误#include <iostream>

#include <fstream>

#include <string>

#include <iomanip>

using namespace stdvoid add_information(string str)

void delete_information(string str)

void edit_information(string str)

void score_count(string str,string name,int low,int high)

void name_Inquiry(string str)

void ID_Inquiry(string str)main()

{

cout<<"本程序完成学生信息管理"<<endl

cout<<endl

string str

cout<<"请输入一个学生信息文件名: "

getline(cin,str)

char ch

cin.get(ch)

cout<<"(1)信息维护 (2)信息查询 (3)成绩统计"<<endl

cout<<"请输入你所要选择的功能编号: "

int number

cin>>number

string name//统计用的科目名

switch(number)

{

case 1:

cout<<"(1)增加学生信息 (2)删除学生信息 (3)修改学生信息"<<endl

cout<<"请输入你所要选择的功能编号: "

cin>>number

switch(number)

{

case 1:

add_information(str)

break

case 2:

delete_information(str)

break

case 3:

edit_information(str)

break

default:

cout<<"对不起,你的输入错误!"

break

}

break

case 2:

cout<<"(1)按姓名查询 (2)按学号查询"<<endl

cout<<"请输入你所要选择的功能编号: "

cin>>number

switch(number)

{

case 1:

name_Inquiry(str)

break

case 2:

ID_Inquiry(str)

break

default:

cout<<"对不起,你的输入错误!"

break

}

break

case 3:

cout<<"请输入科目名:"

cin>>name

cout<<"请输入分数段:(最低分和最高分)"

int score_low,score_high

cin>>score_low>>score_high

score_count(str,name,score_low,score_high)

break

default:

cout<<"对不起,你的输入错误!"

break

} cout<<endl

return 0

}

void add_information(string str)

{

ofstream outstream

outstream.open(str.data(),ios::ate|ios::app)

outstream<<endl

string name

cout<<"请输入新增人的姓名: "

cin>>name

cout<<"请输入学号 语文 数学 英语,用空格分开 :"

string a,b,c,d

cin>>a>>b>>c>>d

outstream.precision(6)//显示精度

outstream<<name<<""<<a<<""<<b<<""<<c<<""<<d//写入文件末尾

outstream.close()

}

void delete_information(string str)

{

ifstream instream

instream.open(str.data())

string name_1,name_2

cout<<"请输入需要删除人的姓名: "

cin>>name_1

string ID,chinese,math,english

ofstream outstream

//暂存的中间文件

outstream.open("temp.txt")

bool flag=0//是否查找到

while(1)

{

//删除操作,自己感觉都有点麻烦

instream>>name_2>>ID>>chinese>>math>>english

if(name_1!=name_2)

{

outstream.precision(6)

outstream<<name_2<<""<<ID<<""<<chinese<<""<<math<<""<<english

outstream<<endl

}

else if (name_1==name_2) flag=1//查找到

if(instream.eof()) break

}

if(!flag) cout<<"没有找到该记录"<<endl

instream.close()

outstream.close()

//将暂存的文件写回到原文件中

ifstream in

ofstream out

in.open("temp.txt")

out.open(str.data())

string line

while(1)

{

getline(in,line)

out<<line

out<<endl

if(in.eof()) break

}

in.close()

out.close()

}

void edit_information(string str)

{

ifstream instream

instream.open(str.data())

string name_1,name_2

cout<<"请输入需要修改人的姓名: "

cin>>name_1

string ID,chinese,math,english

ofstream outstream

//暂存的中间文件

outstream.open("temp.txt")

bool flag=0//是否查找到

while(1)

{

//删除操作,自己感觉都有点麻烦

instream>>name_2>>ID>>chinese>>math>>english

if(name_1==name_2)

{

//找到修改的记录

flag=1

cout<<"请输入新的学号,语文,数学,英语成绩,用空格分开:"

cin>>ID>>chinese>>math>>english

}

outstream.precision(6)

outstream<<name_2<<""<<ID<<""<<chinese<<""<<math<<""<<english

outstream<<endl

if(instream.eof()) break

}

if(!flag) cout<<"没有找到该记录"<<endl

instream.close()

outstream.close()

//将暂存的文件写回到原文件中

ifstream in

ofstream out

in.open("temp.txt")

out.open(str.data())

string line

while(1)

{

getline(in,line)

out<<line

out<<endl

if(in.eof()) break

}

in.close()

out.close()}

void score_count(string str,string name,int low,int high)

{

ifstream instream

instream.open(str.data())

const int max=1000//假设最多有1000条记录

int score[max]

string name_file,ID

int chinese,math,english

int temp=0//统计实际文件中记录的个数

string line

getline(instream,line)//第一行不算入

while(1)

{

instream>>name_file>>ID>>chinese>>math>>english

if(name=="语文") score[temp++]=chinese

else if(name=="数学") score[temp++]=math

else if(name=="英语") score[temp++]=english

if(instream.eof()) break

}

int total=0//分数段内的统计个数

for(int i=0i<tempi++)

if(score[i]>=low &&score[i]<=high) total++

cout<<"分数段在"<<low<<"和"<<high<<"的总个数为: "<<total<<endl

instream.close()

}

void name_Inquiry(string str)

{

ifstream instream

instream.open(str.data())

string name_1,name_2

cout<<"请输入需要查询人的姓名: "

cin>>name_1

string ID,chinese,math,english

bool flag=0

while(1)

{

instream>>name_2>>ID>>chinese>>math>>english

if(name_1==name_2)

{

//找到姓名一样的的记录

flag=1

cout<<name_2<<"的学号 : "<<ID<<" 语文 : "<<chinese<<" 数学 : "<<math<<" 英语 : "<<english

cout<<endl

}

if(instream.eof()) break

}

if(!flag)

cout<<"没有找到该记录"<<endlinstream.close()}

void ID_Inquiry(string str)

{

ifstream instream

instream.open(str.data())

string ID_1

cout<<"请输入需要查询人的ID: "

cin>>ID_1

string ID_2,name,chinese,math,english

bool flag=0

while(1)

{

instream>>name>>ID_2>>chinese>>math>>english

if(ID_1==ID_2)

{

//找到ID一样的的记录

flag=1

cout<<"学号为 : "<<ID_2<<"的姓名为:"<<name<<" 语文 : "<<chinese<<" 数学 : "<<math<<" 英语 : "<<english

cout<<endl

}

if(instream.eof()) break

}

if(!flag)

cout<<"没有找到该记录"<<endlinstream.close()}----------------------------------------------------------其实主要还是对数据文件的操作,理解了难度也不是很大