|
毕业设计互选系统
要求:
1,系统为教师、学生、管理人员分别提供操作界面,三部分分别由不同的同学完成。
2,能登记保存教师信息、学生信息,将信息存入文件。
教师信息包括教师工号、姓名、年龄、职称、所在系、联系电话。学生信息包括学号、姓名、所在系、宿舍、联系电话。
3,能为教师登记毕设课题信息,将课题存入文件。课题信息包括课题编号、课题名、主持老师、面向系、课题内容、课题要求。
4,能为学生查看毕设课题资料。
5,能为学生填写毕设志愿,每个学生可以填写三个课题志愿。学生填写志愿必须跟课题面向系匹配。如果学生没有确定毕设题目,则可以任意修改志愿。课题没有确定选题同学则可以被够资格的同学申请。
6,填写完志愿后,能为教师筛选志愿,确定每个课题选题同学,每个课题只能由一个学生选题。
7,教师筛选志愿完成后,将没有选定毕设课题的同学和没有被选的课题进行随机分配,直到每个学生分配到课题为止。
8,提供每个同学选题统计的报表。
9,其它使系统更完善的功能。
一,要注意的问题
在本版的原创帖集合中,可以找到hjack的<<C/C++常见问题>>。在此就再简单提几点吧。
1,文件包含
调用C++的旧类厍,include的文件有.h的后缀,新的则没有。
旧的:
#include<iostream.h>
新的:
#include<iostream>
using namespace std;
因为新的东西都放在std这个名字空间了。
2,字符串
字符串是以'\0'结束
如char str[]="hello";实际上是“hello\0”
C++的string类这样用 string str="hello";实际上也是“hello\0”
str.c_str()返回指向str字符串的const(常量)指针
3,数组与指针
很多时候数组和指针可以同等对待,一般使用不会出现问题。但是千万不要直接使用没有指向指定内存的指针。简单地说,用指针前,它一定指向某数组、变量或用new分配的空间。
二,字符串分解
这里介绍一个函数。
/*
原型:char *strtok(char *s, char *delim);
功能:分解字符串为一组标记串。s为要分解的字符串,delim为分隔符字符串。
说明:首次调用时,s必须指向要分解的字符串,随后调用要把s设成NULL。
strtok在s中查找包含在delim中的字符并用NULL('\0')来替换,
直到找遍整个字符串。返回指向下一个标记串。
当没有标记串时则返回空字符NULL。
*/
- #include<iostream>
- using namespace std;
- int main()
- {
- char str[]="日期:2006-5-1,天气:晴,标题:今天是五一";
- const char *delimiter=",";
- char* temp;
- temp=strtok(str,delimiter);
- while (temp!=NULL)
- {
- cout<<temp<<endl;
- temp=strtok(NULL,delimiter);
- }
- }
复制代码
按理说strtok应该在string或string.h这个头文件里的,可是我没写#include<string>这句也通过了编译。
在http://www.cplusplus.com/ref/cstring/strtok.html有较详细介绍(虽然是英文的,也不难看懂)。
三,读写文件(C++)
先看代码
#include<fstream>
#include<iostream>
using namespace std;
//读文本文件,getline比较好用
//file:read.cpp
int main()
{
char buffer[257];
fstream in("read.cpp",ios::in); //或者ifstream in("read.cpp");
if(in.is_open())
{
while(in.getline(buffer,256))//buffer指读入到的缓存,256指要读入的大小,如果小于指定大小,会写入'\0'
cout<<buffer<<endl;
in.close();//用完了关闭是好习惯
}
else
cout<<"无法打开文件"<<endl;
return 0;
}
写文件
- #include<fstream>
- #include<iostream>
- #include<string>
- using namespace std;
- int main()
- {
- char buffer[]="从数组写入一行";
- const string filename("test.txt");
- fstream out(filename.c_str(),ios::out);
- if(!out)
- {
- cout<<"error"<<endl;
- exit(1);
- }
- out<<"用<<写入的一行"<<endl;
- out.write(buffer,strlen(buffer));
- }
复制代码
文件读写操作在http://www.cplusplus.com/doc/tutorial/files.html 也有详细介绍。
读写文件(C)
读文件
/*
**函数名: fgets
**功 能: 从流中读取一字符串
**用 法: char *fgets(char *string, int n, FILE *stream);
**程序例:
*/
//file:readline.c
#include <string.h>
#include <stdio.h>
int main(void)
{
FILE *stream;
char msg[256];
stream = fopen("readline.c", "r");
while(fgets(msg, 256, stream)!=NULL)
printf("%s", msg);
fclose(stream);
return 0;
}
写文件
/*
*函数名: fwrite
*功 能: 整块数据的读写函数(可以写入一个结构体)
*用 法: int fwrite(void *ptr, int size, int nitems, FILE *stream);
*size是指输入块的大小(单位:字节),如字符为1,nitems指块数
*/
#include <string.h>
#include <stdio.h>
int main(void)
{
FILE *stream;
unsigned char msg[] = "This is a test\n";
unsigned char msg2[]="This is line 2\n";
stream = fopen("test.txt", "w+");
fwrite(msg,1,strlen(msg),stream);
fwrite(msg2,1,strlen(msg2),stream);
fclose(stream);
return 0;
}
当然,你还可以用fgetc,fgets,fputc,fputs等来操作文件
更详细介绍在http://www.cplusplus.com/ref/cstdio/
四,继承、多态(C++)
以前大一学的是C语言,现在老师建议用C++来实现。有些同学才开始接触C++,难免以为C++只是比C多了个类而已,然后自然想到定义Student类、Teacher类,在类里写一些函数操作。当然,方法多种多样。这里有个想法:使用C++的继承、多态。具体如何,各人有不同实现方法。我只给个最简单的例子说明C++的继承、多态。
#include<iostream>
using namespace std;
class Person
{
public:
virtual void print()=0;
};
class Student:public Person
{
public:
void print()
{
cout<<"print from Student"<<endl;
}
};
class Teacher:public Person
{
public:
void print()
{
cout<<"print from Teacher"<<endl;
}
};
void f(Person*p)
{
p->print();
}
int main()
{
Student s;
Teacher t;
f(&s);
f(&t);
//system("pause");
return 0;
}
/*
**把Person类的函数定义纯虚函数(相当JAVA的接口),然后Student类和Teacher类分别继承Person。
**void f(Person*p);可以接受Person子类指针,根据不同子类调用不同的print()函数。
*/
很多东西要我们自己慢慢尝试、探索、实现。
有不当或错误之处,请批评指正,谢谢!
[ 本帖最后由 powerwind 于 2006-6-28 00:55 编辑 ] |
评分
-
2
查看全部评分
-
|