C++学生选修课程系统
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C++学生选修课程系统相关的知识,希望对你有一定的参考价值。
用C++编写学生选修课程系统假定有n门课程,每门课程有课程编号,课程名称,课程性质,总学时,授课学时,实验或上机学时,学分,开课学期等信息,学生可按要求(如总学分不得少于60)自由选课。设计一选修课程系统,使之能提供以下功能:1、系统以菜单方式工作2、课程信息录入功能(课程信息用文件保存)3、课程信息浏览功能4、查询功能:(至少一种查询方式) 1)按学分查询 2)按课程性质查询5、学生选修课程
参考技术A #include <iostream>#include <fstream>
#include <string>
#include <conio.h>
using namespace std;struct Course
string num; //课程编号
string name; //课程名称
string type; //课程性质
int period; //总学时
int classPeriod; //授课学时
int expPeriod; //实验学时或上机学时
int credit; //学分
string beginDate; //开课时间
Course *next;
;void InitList (Course *&L)
L = new Course;
L->next = NULL;
ostream &operator << (ostream &output, Course *&c)
output << c->num << '\t' << c->name << '\t' << c->type << '\t' << c->period
<< '\t' << c->classPeriod << '\t' << c->expPeriod << '\t' << c->credit
<< '\t' << c->beginDate << endl;
return output;
istream &operator >> (istream &input, Course *&c)
//cout << "开始输入……" << endl;
input >> c->num >> c->name >> c->type >> c->period
>> c->classPeriod >> c->expPeriod >> c->credit >> c->beginDate;
return input;
void SaveInfo (Course *L)
Course *p = L->next;
ofstream outfile ("course.txt", ios::out);
if (!outfile)
cerr << "open error!" << endl;
exit (1);
while (p != NULL)
outfile << p;
p = p->next;
outfile.close ();
void ReadInfo (Course *&L)
Course *r = L, *s;
ifstream infile ("course.txt", ios::in);
if (!infile)
cerr << "open error!" << endl;
exit (1);
while (!infile.eof ())
s = new Course;
infile >> s;
if (!infile.eof ())
r->next = s;
r = s;
r->next = NULL;
infile.close ();
void AddInfo (Course *L)
system ("cls");
InitList (L);
Course *s;
s = new Course; cout << "请输入以下信息:" << endl; cout << "课程编号 课程名称 课程性质 总学时 授课学时 实验或上机学时 学分 开课学期" << endl;
cin >> s;
//cout << "输入完毕……" << endl; cout << "是否保存信息?\n(1)是\n(2)否\n" << endl; ofstream outfile ("course.txt", ios::app);
if (!outfile)
outfile.close ();
ofstream outfile ("course.txt",ios::out);
outfile.close (); ReadInfo (L);
switch (getch ())
case '1':
s->next = L->next;
L->next = s;
SaveInfo (L);
cout << "保存成功!" << endl;
break;
case '2':
break;
default:
break;
system ("pause");
void DeleteInfo (Course *L)
system("cls");
InitList (L);
ReadInfo (L);
Course *p = L, *q = p->next;
cout << "请输入课程编号:";
string n;
cin >> n; while ((q != NULL) && (q->num != n))
p = q;
q = q->next;
if (q == NULL)
cout << "无此编号的课程!" << endl;
else
cout << "该课程信息如下:" << endl;
cout << q << endl;
cout << "确认删除该课程信息?\n(1)确认\n(2)取消\n" << endl;
switch (getch ())
case '1':
p->next = q->next;
delete q;
SaveInfo (L);
cout << "删除成功!" << endl;
break;
case '2':
break;
default:
break;
system ("pause");
void SearchByCredit (Course *L)
system ("cls");
InitList (L);
ReadInfo (L);
Course *p = L->next; cout << "请输入学分:";
int c;
cin >> c; bool flag = false;
while (p != NULL)
if (p->credit == c)
flag = true;
cout << p;
p = p->next;
if (flag == false)
cout << "没有此学分的课程!" << endl << endl;
system ("pause");
void SearchByType (Course *L)
system ("cls");
InitList (L);
ReadInfo (L);
Course *p = L->next;
cout << "请输入课程性质:";
string t;
cin >> t; bool flag = false;
while (p != NULL)
if (p->type == t)
cout << p;
flag = true;
p = p->next;
if (flag == false)
cout << "无此性质的课程!" << endl << endl;
system ("pause");
void DispInfo (Course *L)
system ("cls");
InitList (L);
ReadInfo (L);
Course *p = L->next;
while (p != NULL)
cout << p;
p = p->next;
cout << endl << endl;
system ("pause");
void Search ()
Course *l;
InitList (l);
while (1)
system ("cls");
cout << endl << endl << endl;
cout << "\t*************************************************" << endl;
cout << "\t* *" << endl;
cout << "\t* 请选择查询方式 *" << endl;
cout << "\t* (1)按学分查询 *" << endl;
cout << "\t* (2)按性质查询 *" << endl;
cout << "\t* (3) 返回 *" << endl;
cout << "\t* *" << endl;
cout << "\t*************************************************" << endl; switch (getch ())
case '1':
SearchByCredit (l);
break;
case '2':
SearchByType (l);
break;
case '3':
return;
default:
break;
void menu ()
Course *l;
InitList (l);
while (1)
system ("cls");
cout << endl << endl << endl;
cout << "\t*****************************************************" << endl;
cout << "\t* *" << endl;
cout << "\t* 学生选课系统 *" << endl;
cout << "\t* (1) 信息录入 *" << endl;
cout << "\t* (2) 信息查询 *" << endl;
cout << "\t* (3) 信息显示 *" << endl;
cout << "\t* (4) 信息删除 *" << endl;
cout << "\t* (0) 退出 *" << endl;
cout << "\t* *" << endl;
cout << "\t*****************************************************" << endl; switch (getch ())
case '1':
AddInfo (l);
break;
case '2':
Search ();
break;
case '3':
DispInfo (l);
break;
case '4':
DeleteInfo (l);
break;
case '0':
cout << "谢谢使用!" << endl;
exit (0);
default:
break;
int main ()
menu ();
return 0;
学生可按要求(如总学分不得少于60)自由选课……这句话我不知道是什么意思,所以没有编选课的那段
查询选修了java课程的学生的姓名怎么操作?
这是三个表的数据
Select distinct s.name from student sLeft Join student_kc sk
on sk.s_number = s.s_number
Left Join kc k
on k.k_number = sk.k_number
and k.k_name = 'java'
或者
Select distinct s.name from student s, student_kc sk, kc k
where sk.s_number = s.s_number
and k.k_number = sk.k_number
and k.k_name = 'java' 参考技术A 电容器还可以消除脉动。如果传导直流电压的线路含有脉动或尖峰
以上是关于C++学生选修课程系统的主要内容,如果未能解决你的问题,请参考以下文章