用C++语言 编写 课程设计的安排。。

作者&投稿:荀伊 (若有异议请与网页底部的电邮联系)
跪求C++简单的矩阵运算,课程设计,一定要用C++编写啊 2.基本要求: 要求用C++语言编程,在Vis...~

亲 邮箱都不留

你要把你做的答案贴出来,别人才能帮你修改啊。

#include<fstream.h>
#include<iostream.h>
#include<iomanip.h>
#include<string.h>
#include<stdlib.h>
#define M 20
#define N 12
#define MAX 100
class Fphone //用户信息类的定义
{
char name[M]; // 姓名
char phone_num[N]; //电话号码
public:
Fphone(char *na="",char *ph="")
{ strcpy(name,na);
strcpy(phone_num,ph);
}
char*getname(); //获取姓名
char*getphone_num(); //获取电话号码
void setname(char*a); //设置姓名
void setphone_num(char*a); //设置电话号码
void disp(); //显示用户信息
};
char *Fphone::getname()
{ return name;
}
char *Fphone::getphone_num()
{ return (phone_num);
}
void Fphone::setname(char *a)
{ strcpy(name,a);
}
void Fphone::setphone_num(char*a)
{ strcpy(phone_num,a);
}
void Fphone::disp()
{ cout<<"姓名:"<<name<<'\t'<<"电话号码:"<<phone_num<<endl;
}
class UserDatabase //用户信息表类的定义
{ int nElem; //用户信息表中的元素个数,即当前记录总数
int Maxu; //最多的用户
Fphone *user; //指向用户信息表的指针
public:
UserDatabase() //构造函数,初始化用户信息表,将user.txt文件中数据读到User[]中
{ nElem=0;
Maxu=50;
user=new Fphone[Maxu];
fstream in;
in.open("user.txt",ios::in|ios::nocreate); //打开文件
for(int i=0;(!in.eof());i++)
{ in>>user[i].getname();in>>user[i].getphone_num();
nElem++;
}
in.close();
}
~UserDatabase() //析构函数,将user[]写入user.txt文件中
{ fstream out;
Fphone *p=NULL;
p=user;
out.open("user.txt",ios::out,filebuf::sh_none);
for(int i=0;i<nElem;i++)
{ out<<setw(20)<<((p+i)->getname())<<setw(15)
<<((p+i)->getphone_num())<<endl;
}delete []user;
out.close();
}
void clear() //删除所有用户信息
{ char ord;
cout<<"确定删除吗?(选择:[y]是;[n]否)\a\a"<<endl;
do
{ cin>>ord;
if(ord=='N'||ord=='n') return;
else if(ord=='Y'||ord=='y')
{ delete[Maxu]user;
user=0;
cout<<"删除成功啦!"<<endl;
nElem=0;
return;
}
else cout<<"请重新输入(选择:[y]是;[n]否)\a\a"<<endl;
}
while(ord!='n'||ord!='N'||ord!='y'||ord!='Y');
}
void add_record(char *na,char*ph_num) //添加用户信息,插入用户后仍按升序排列
{ if (nElem==0)
{ nElem++;
user->setname(na);
user->setphone_num(ph_num);
}
else if(nElem<Maxu)
{ for(int i=nElem-1;i>=0;i--)
{ if(strcmp((user+i)->getname(),na)>0)
{ (user+i+1)->setname(((user+i)->getname()));
(user+i+1)->setphone_num(((user+i)->getphone_num()));
}
else break;
}
(user+i+1)->setname(na);
(user+i+1)->setphone_num(ph_num);
nElem++;
}
else cout <<"空间不足,无法添加!"<<endl;
}
Fphone *getuser() //返回user指针
{ return(user); }
void delete_record(Fphone *p,int k) //删除用户信息
{ char con;
cout<<"确认删除?(Y/N)";
cin>>con;
if (con=='N'||con=='n') return;
else if (con=='Y'||con=='y')
{ for(int i=k;i<nElem;i++)
{ user[i]=user[i+1]; }
nElem--;
cout<<"已删除!"<<endl;
return;
}
else
{ cout<<"输入错误!"<<endl;
system("pause");
return;
}
}
void modify_record(Fphone *p,char*ph_num)//修改用户信息
{
p->setphone_num(ph_num);
}
Fphone *query(char *na) //按姓名查找 顺序查找,这里也可以用折半
{ Fphone *p=user;
int i=0;
while(1)
{ if(strcmp(p->getname(),na)==0)
return p;
p++;
if(i++==nElem)
break;
}
return NULL;
}
void sorta_name() //按姓名升序排序 插入排序法
{ Fphone temp;
int i,j;
for(i=1;i<nElem;i++)
{ temp=user[i];
for(j=i-1;j>=0&&(strcmp(temp.getname(),user[j].getname())<0);j--)
{ strcpy(user[j+1].getname(),user[j].getname());
strcpy(user[j+1].getphone_num(),user[j].getphone_num());
}
strcpy(user[j+1].getname(),temp.getname());
strcpy(user[j+1].getphone_num(),temp.getphone_num());
}
}
void sorta_phonenum() //按电话号码升序排序 选择排序法
{ int i,j,p;
Fphone temp;
for(i=0;i<nElem-1;i++)
{ p=i;
for(j=i+1;j<nElem;j++)
if(strcmp(user[j].getphone_num(),user[p].getphone_num())<0) p=j;
if(p!=i)
{ strcpy(temp.getname(),user[p].getname());
strcpy(temp.getphone_num(),user[p].getphone_num());
strcpy(user[p].getname(),user[i].getname());
strcpy(user[p].getphone_num(),user[i].getphone_num());
strcpy(user[i].getname(),temp.getname());
strcpy(user[i].getphone_num(),temp.getphone_num());
}
}
}
void sort_name() //按姓名降序排序,将排成升序的对象数组逆向放置
{ Fphone temp;
int i,m=(nElem+1)/2;
for(i=0;i<m;i++)
{ strcpy(temp.getname(),user[i].getname());
strcpy(temp.getphone_num(),user[i].getphone_num());
strcpy(user[i].getname(),user[nElem-i-1].getname());
strcpy(user[i].getphone_num(),user[nElem-i-1].getphone_num());
strcpy(user[nElem-i-1].getname(),temp.getname());
strcpy(user[nElem-i-1].getphone_num(),temp.getphone_num());
}
}
void sort_phonenum() //按电话号码降序排序 冒泡排序法
{ Fphone temp;
int i,m=(nElem+1)/2;
for(i=0;i<m;i++)
{ strcpy(temp.getname(),user[i].getname());
strcpy(temp.getphone_num(),user[i].getphone_num());
strcpy(user[i].getname(),user[nElem-i-1].getname());
strcpy(user[i].getphone_num(),user[nElem-i-1].getphone_num());
strcpy(user[nElem-i-1].getname(),temp.getname());
strcpy(user[nElem-i-1].getphone_num(),temp.getphone_num());
}
}
void disp()
{ int i,n=0;
cout<<setw(22)<<"姓名"<<setw(14)<<"电话号码"<<endl;
for(i=0;i<nElem;i++)
{
cout<<setw(22)<<(user+i)->getname()
<<setw(14)<<(user+i)->getphone_num()<<endl;
n++;
if(n%10==0)
{ system("pause");
system("cls");
}
}
cout<<endl;
}
};
void menu()
{ cout<<" 请选择以下功能:"<<endl;
cout<<" 1-增加记录"<<endl;
cout<<" 2-修改记录"<<endl;
cout<<" 3-删除记录"<<endl;
cout<<" 4-查找(按姓名)"<<endl;
cout<<" 5-排序"<<endl;
cout<<" 6-显示记录"<<endl;
cout<<" 7-全删"<<endl;
cout<<" 0-退出"<<endl;
cout<<" 输入选择:"<<endl;
}
void main()
{ cout<<"************************************************** "<<endl;
cout<<" "<<endl;
cout<<" 欢迎使用电话簿管理系统 "<<endl;
cout<<" 祝您使用愉快 "<<endl;
cout<<" "<<endl;
cout<<"***************************************************** "<<endl;
system("pause");
while(1)
{ UserDatabase s;
system("cls");
menu();
int k;
cin>>k;
switch(k)
{ case 1:
{ system("cls") cout<<"*****************************************"<<endl; cout<<" 增加记录 "<<endl;
char na[20],ph_num[12];
Fphone *t=NULL;
char w;
do
{ cout<<"请输入您要增加的用户的姓名";
cin>>na;
t=(s.query(na));
if(t)
{ cout<<"用户已经存在,添加失败!!!"<<endl; }
else
{ cout<<"请输入用户的电话号码";
cin>>ph_num;
s.add_record(na,ph_num);
cout<<"您添加的信息为:";
cout<<"姓名:"<<na<<'\t'<<"电话号码:"<<ph_num<<endl;
cout<<"成功添加"<<endl;
}
cout<<"是否继续?(Y or N)"<<endl;
cin>>w;
}
while(w=='Y');
break;
}
case 2:
{ system("cls"); cout<<"***************************************"<<endl;
cout<<" 修改记录 "<<endl;
cout<<"***************************************"<<endl;
char na[M],ph_num[N];
Fphone *t=NULL;
char w;
do
{ cout<<"请输入您要修改的用户的姓名";
cin>>na;
t=s.query(na);
if(!t)
cout<<"没有该用户!"<<endl;
else
{ cout<<"该用户原号码为:"<<t->getphone_num()<<endl;
cout<<"请输入新的电话号码";
cin>>ph_num;
s.modify_record(t,ph_num);
cout<<"成功修改"<<endl;
}
cout<<"是否继续?(Y or N)"<<endl;
cin>>w;
}
while(w=='Y');
break;
}
case 3:
{ system("cls"); cout<<"********************************************"<<endl;
cout<<" 删除记录 "<<endl; cout<<"************** ***************************"<<endl;
char w;
char na[M];
int k;
Fphone *p;
do
{ cout<<"请输入您要删除的用户的姓名";
cin>>na;
p=s.query(na);
if(p==0)
cout<<"没有该用户!"<<endl;
else
{ (*p).disp();
k=p-s.getuser();
s.delete_record(p,k);
}
cout<<"是否继续?(Y or N)"<<endl;
cin>>w;
}
while(w=='Y');
break;
}
case 4:
{ system("cls"); cout<<"*********************************"<<endl;
cout<<" 查询记录 "<<endl;
cout<<"**********************************"<<endl;
char na[M];int p=1;
Fphone *t=NULL;
char w;
do
{ cout<<"请输入您要查询的用户的姓名";
cin>>na;
t=s.query(na);
if(t)
{
cout<<"姓名:"<<t->getname()<<endl;
cout<<"电话号码:"<<t->getphone_num()<<endl;
}
else
cout<<"对不起,没有此人信息!"<<endl;
cout<<"是否继续?(Y or N)"<<endl;
cin>>w;
}
while(w=='Y');
break;
}
case 5:
{ system("cls");
cout<<" 请选择排序方式 "<<endl;
cout<<" 1.按姓名(升序) "<<endl;
cout<<" 2.按电话号码(升序) "<<endl;
cout<<" 3.按姓名(降序) "<<endl;
cout<<" 4.按电话号码(降序) "<<endl;
cout<<" 请输入你的选择: "<<endl;
int k;
cin>>k;
switch(k)
{ case 1:
s.sorta_name();
cout<<"排序完成"<<endl;
system("cls");
break;
case 2:
s.sorta_phonenum();
cout<<"排序完成"<<endl;
system("cls");
break;
case 3:
s.sort_name();
cout<<"排序完成"<<endl;
system("cls");
break;
case 4:
s.sort_phonenum();
cout<<"排序完成"<<endl;
system("cls");
break;
}
}
case 6:
{ system("cls");
cout<<"*****************************************"<<endl;
cout<<" 显示记录 "<<endl;
cout<<"*****************************************"<<endl;
s.disp();
system("pause");
break;
}
case 7:
{ system("cls");
cout<<"您确定要删除所有记录吗?(Y or N)"<<endl;
char q;
cin>>q;
if(q=='Y'||q=='y')
{ cout<<"*********************************"<<endl;
cout<<" 全部删除记录 "<<endl;
cout<<"*********************************"<<endl;
s.clear();
}
else break;
system("pause");
break;
}
case 0:
{ system("cls");
cout<<"谢谢使用,再见!"<<endl;
exit(0);
}
default:
cout<<"不存在该选择,请重新输入要进行的操作:"<<endl;
system("pause");
break;
}
}
}

我这是源代码已经调试过了,在VC++上运行成功了。
#include "stdio.h" /*I/O函数*/
#include "stdlib.h" /*其它说明*/
#include "string.h" /*字符串函数*/
#include "conio.h" /*屏幕操作函数*/
#include "mem.h" /*内存操作函数*/
#include "ctype.h" /*字符操作函数*/
#include "alloc.h" /*动态地址分配函数*/
struct score
{
int mingci;
char xuehao[8];
char mingzi[20];
float score[6];
}data,info[1000];
int i,j,k=0;
char temp[20],ch;
FILE *fp,*fp1;

void shuru()
{
if((fp=fopen("s_score.txt","ab+"))==NULL)
{
printf("cannot open this file.\n");
getch();exit(0);
}
for(i=0;i<=1000;i++)
{
printf("\nPlease shuru xuehao:");
gets(data.xuehao);
printf("Please shuru mingzi:");
gets(data.mingzi);
printf("Please shuru yuwen score:");
gets(temp);data.score[0]=atof(temp);
printf("Please shuru shuxue score:");
gets(temp);data.score[1]=atof(temp);
printf("Please input yingyu score:");
gets(temp);data.score[2]=atof(temp);
printf("Please shuru wuli score:");
gets(temp);data.score[3]=atof(temp);
printf("Please shur huaxue score:");
gets(temp);data.score[4]=atof(temp);
data.score[5]=data.score[0]+data.score[1]+data.score[2]+data.score[3]+data.score[4];
fwrite(&data,sizeof(data),1,fp);
printf("another?y/n");
ch=getch();
if(ch=='n'||ch=='N')
break;
} fclose(fp);
}
void xianshi()
{
float s;int n;
if((fp=fopen("s_score.txt","rb+"))==NULL)
{
printf("Cannot reading this file.\n");
exit(0);
}
for(i=0;i<=1000;i++)
{
if((fread(&info[i],sizeof(info[i]),1,fp))!=1)
break;
}
printf("\nxuehao mingzi yuwen shuxue yingyu wuli huauxue zhongfen\n");
for(j=0,k=1;j<i;j++,k++)
{
info[j].mingci=k;
printf("%6s %8s %3.1f %3.1f %3.1f %3.1f %3.1f %3.1f\n",info[j].xuehao,info[j].mingzi,info[j].score[0],info[j].score[1],info[j].score[2],info[j].score[3],info[j].score[4],
info[j].score[5]);
}
getch();
fclose(fp);
}

void xiugai()
{
if((fp=fopen("s_score.txt","rb+"))==NULL||(fp1=fopen("temp.txt","wb+"))==NULL)
{
printf("Cannot open this file.\n");
exit(0);
}
printf("\nPLease shuru xiugai xuehao:");
scanf("%d",&i); getchar();
while((fread(&data,sizeof(data),1,fp))==1)
{
j=atoi(data.xuehao);
if(j==i)
{
printf("xuehao:%s\nmingzi:%s\n",data.xuehao,data.mingzi);
printf("Please shuru mingzi:");
gets(data.mingzi);
printf("Please shuru yuwen score:");
gets(temp);data.score[0]=atof(temp);
printf("Please shuru shuxue score:");
gets(temp);data.score[1]=atof(temp);
printf("Please input yingyu score:");
gets(temp);data.score[2]=atof(temp);
printf("Please input wuli score:");
gets(temp);data.score[3]=atof(temp);
printf("Please input huaxue score:");
gets(temp);data.score[4]=atof(temp);
data.score[5]=data.score[0]+data.score[1]+data.score[2]+data.score[3]+data.score[4];

} fwrite(&data,sizeof(data),1,fp1);
}
fseek(fp,0L,0);
fseek(fp1,0L,0);
while((fread(&data,sizeof(data),1,fp1))==1)
{
fwrite(&data,sizeof(data),1,fp);
}

fclose(fp);
fclose(fp1);
}
void chazhao()
{
if((fp=fopen("s_score.txt","rb"))==NULL)
{
printf("\nCannot open this file.\n");
exit(0);
}
printf("\nPLease shuru xuehao chakan:");
scanf("%d",&i);
while(fread(&data,sizeof(data),1,fp)==1)
{
j=atoi(data.xuehao);
if(i==j)
{
printf("xuehao:%s mingzi:%s\nyuwen:%f\n shuxue:%f\n yingyu:%f\n wuli:%f\n huaxue:%f\n ",data.xuehao,data.mingzi,data.score[0],data.score[1],data.score[2],data.score[3],data.score[4],data.score[5]);
}getch();
}
}
void shanchu()
{
if((fp=fopen("s_score.txt","rb+"))==NULL||(fp1=fopen("temp.txt","wb+"))==NULL)
{
printf("\nopen score.txt was failed!");
getch();
exit(0);
}
printf("\nPlease input ID which you want to del:");
scanf("%d",&i);getchar();
while((fread(&data,sizeof(data),1,fp))==1)
{
j=atoi(data.xuehao);
if(j==i)
{

printf("Anykey will delet it.\n");
getch();
continue;
}
fwrite(&data,sizeof(data),1,fp1);
}
fclose(fp);
fclose(fp1);
remove("s_score.txt");
rename("temp.txt","s_score.txt");
printf("Data delet was succesful!\n");
printf("Anykey will return to main.");
getch();
}
main()
{
while(1)
{
clrscr(); /*清屏幕*/
gotoxy(1,1); /*移动光标*/
textcolor(YELLOW); /*设置文本显示颜色为黄色*/
textbackground(BLUE); /*设置背景颜色为蓝色*/
window(1,1,99,99); /* 制作显示菜单的窗口,大小根据菜单条数设计*/
clrscr();
printf("*************welcome to use student manage******************\n");
printf("*************************menu********************************\n");
printf("* ========================================================= * \n");
printf("* 1>shuru 2>xiugai * \n");
printf("* 3>shanchu 4>chazhao * \n");
printf("* 5>xianshi 6>exit * \n");
printf("* * \n");
printf("* --------------------------------------------------------- * \n");
printf(" Please input which you want(1-6):");
ch=getch();
switch(ch)
{
case '1':shuru();break;
case '2':xiugai(); break;
case '3':shanchu(); break;
case '4':chazhao(); break;
case '5':xianshi(); break;
case '6':exit(0);
default: continue;
}
}



永清县19814262198: 用C++语言 编写 课程设计的安排.. -
并肾头孢: #include#include#include#include#include#define M 20#define N 12#define MAX 100clas...

永清县19814262198: C++课程设计该怎么弄呢 -
并肾头孢: 老师说是最简单的一个,可我足足搞了一个星期啊!至于步骤的话!我曾经搞过一个“电子英汉词典”,再讲每部分细化为一些函数,再来编写我也做过这种任务,刚学完的话我建议你自己搞一个“电子英汉词典”,“或者通讯录管理系统”,可视化我觉得比较麻烦:我觉得先确定好你要做什么程序!然后就分下来程序具体有几部分构成.之后我建议你话多点时间去调试程序,这我觉得是最费时间的.然后别的就随便可以了,主心骨是程序

永清县19814262198: 用C++语言 编写 课程设计的安排.. -
并肾头孢: #include<fstream.h>

永清县19814262198: 用C++怎么写操作系统的课程设计?
并肾头孢: C++ 多线程也不是很难 孙鑫有个教程讲VC的 里边有C++多线程部分 #include <windows.h> #include <iostream.h> DWORD WINAPI Fun1Proc(LPVOID lpParameter);//thread data DWORD WINAPI Fun2Proc(LPVOID lpParameter);//thread data ...

永清县19814262198: C++课程设计
并肾头孢: #include"stdafx.h" #define MAX 100 #include<iostream> #include<string> using namespace std; class Score { public: Score(); Score(double m,double d,double c,double e,double i); void SetScore(double m,double d,double c,double e,double i); ...

永清县19814262198: 用c++做个记事本程序 课程设计 思路 -
并肾头孢: 用mfc创建一个 单文档 工程 就直接是一个 记事本程序了;自己做的思路: 1、如果是但文本, 需要一个, textbox 2、需要保存,打开 文件的功能; 3、需要定位光标位置的功能,如果是textbox则自带了

永清县19814262198: 用C++怎么编写的求两条直线交点的课程设计 -
并肾头孢: 我的粗略答案#include <iostream.h>class line { double a,b,c; public: line ( double a1, double b1, double c1) {a=a1;b=b1;c=c1;} friend void setpoint(line &A,line &B); }; void setpoint(line &A,line &B) { double x; if(A.a/B.a!=A.b/B.b) {x=-100;do{if(( (-A.c-...

永清县19814262198: C++程序设计:安排研究生课程表.
并肾头孢: 数据结构(C语言版) C++面向对象程序设计数据库系统设计与原理软件工程系统可以参看一下一些计算机专业课程表,但最基本原则是先学一门语言他是以后所有

永清县19814262198: 求c++程序课设 -
并肾头孢: #include#include#include#include using namespace std;/* 各种头文件声明*/ char number[1000];//这是产生的随机数,变换成字符串类型,以便于比较 int num;//产生的随机数 int length;//随机数长度 char inputNumber[1000]={0};//用户输入...

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网