1. 用Java(面向对象程序设计)编写小型学生理财系统
除非谁有现成的代码还有时间。
2. 求一个c语言面向对象程序设计的程序-学生成绩管理系统
面向对象的只学过java,没听说过c语言面向对象的
3. 面向对象程序设计编写一个简单的学生成绩管理系统
#include
#include
#include
#define LEN sizeof(struct scorenode)
#define DEBUG
#include
struct scorenode
{int number;/*学号*/
char name[10];/*姓名*/
float computer;/*计算机 成绩*/
float english;/*英语成绩*/
float math;/*数学成绩 */
struct scorenode *next;
};
typedef struct scorenode score;
int n,k;/*n,k为全局变量,本程序中的函数均可以使用它*/
/*==============================================================================================*/
score *creat(void)/*函数creat,功能:创建链表,此函数带回一个指向链表头的指针*/
{
score*head;
score *p1,*p2,*p3,*max;
int i,j;
float fen;
char t[10];
n=0;
p1=p2=p3=(score *)malloc(LEN);head=p3; /*开辟一个新单元输入学生相关资料*/
printf("请输入学生资料,输0退出!\n");
repeat1: printf("请输入学生学号(学号应大于0):");
scanf("%d",&p1->number);
while(p1->number<0)
{getchar();
printf("输入错误,请重新输入学生学号:");
scanf("%d",&p1->number);}
if(p1->number==0)
goto end;
else
{
p3=head;
if(n>0)
{for(i=0;i<n;i++)
{if(p1->number!=p3->number)
p3=p3->next;
else
{printf("学号重复,请重输!\n");
goto repeat1;
}
}
}
}
printf("请输入学生姓名:");
scanf("%s",&p1->name);
printf("请输入计算机 成绩(0~100):");
scanf("%f",&p1->computer);
while(p1->computercomputer>100)
{getchar();
printf("输入错误,请重新输入计算机 成绩");
scanf("%f",&p1->computer);}
printf("请输入英语成绩(0~100):");
scanf("%f",&p1->english);
while(p1->englishenglish>100)
{getchar();
printf("输入错误,请重新输入英语成绩");
scanf("%f",&p1->english);}
printf("请输入数学成绩(0~100):");
scanf("%f",&p1->math);
while(p1->mathmath>100)
{getchar();
printf("输入错误,请重新输入数学成绩");
scanf("%f",&p1->math);}
head=NULL;
while(p1->number!=0)
{
n=n+1;
if(n==1)
head=p1;
else
p2->next=p1;
p2=p1;
p1=(score *)malloc(LEN);
printf("请输入学生资料,输0退出!\n");
repeat2:printf("请输入学生学号(学号应大于0):");
scanf("%d",&p1->number);
while(p1->number<0)
{getchar();
printf("输入错误,请重新输入学生学号:");
scanf("%d",&p1->number);}
if(p1->number==0)
goto end;
else
{
p3=head;
if(n>0)
{for(i=0;i<n;i++)
{if(p1->number!=p3->number)
p3=p3->next;
else
{printf("学号重复,请重输!\n");
goto repeat2;
}
}
}
}
printf("请输入学生姓名:");
scanf("%s",&p1->name);
printf("请输入计算机 成绩(0~100):");
scanf("%f",&p1->computer);
while(p1->computercomputer>100)
{getchar();
printf("输入错误,请重新输入计算机 成绩");
scanf("%f",&p1->computer);}
printf("请输入英语成绩(0~100):");
scanf("%f",&p1->english);
while(p1->englishenglish>100)
{getchar();
printf("输入错误,请重新输入英语成绩");
scanf("%f",&p1->english);}
printf("请输入数学成绩(0~100):");
scanf("%f",&p1->math);
while(p1->mathmath>100)
{getchar();
printf("输入错误,请重新输入数学成绩");
scanf("%f",&p1->math);}
}
end: p1=head;
p3=p1;
for(i=1;i<n;i++)
{
for(j=i+1;j<=n;j++)
{
max=p1;
p1=p1->next;
if(max->number>p1->number)
{
k=max->number;
max->number=p1->number;
p1->number=k;
strcpy(t,max->name);
strcpy(max->name,p1->name);
strcpy(p1->name,t);
fen=max->computer;
max->computer=p1->computer;
p1->computer=fen;
fen=max->english;
max->english=p1->english;
p1->english=fen;
fen=max->math;
max->math=p1->math;
p1->math=fen;
}
}
max=head;p1=head;/*重新使max,p指向链表头*/
}
p2->next=NULL;/*链表结尾*/
printf("输入的学生数为:%d个!\n",n);
return(head);
}
/*==============================================================================================*/
score *add2311(score *head,score *stu)/*函数add2311,功能将所有学生资料按学号排序*/
{
score *p0,*p1,*p2,*p3,*max;
int i,j;
float fen;
char t[10];
p3=stu=(score *)malloc(LEN);/*开辟一个新单元*/
printf("\n输入要增加的学生的资料!");
repeat4: printf("请输入学生学号(学号应大于0):");
scanf("%d",&stu->number);
/*输入学号,学号应大于0*/
while(stu->number<0)
{getchar();
printf("输入错误,请重新输入学生学号:");
scanf("%d",&stu->number);}/*输入错误,重新输入学号*/
if(stu->number==0)
goto end2;/*当输入的学号为0时,转到末尾,结束追加*/
else
{
p3=head;
if(n>0)
{for(i=0;i<n;i++)
{if(stu->number!=p3->number)
p3=p3->next;
else
{printf("学号重复,请重输!\n");
goto repeat4;
}
}
}
}
/******************************************************/
printf("输入学生姓名:");
scanf("%s",stu->name);
printf("请输入计算机 成绩(0~100):");
scanf("%f",&stu->computer);
while(stu->computercomputer>100)
{getchar();
printf("输入错误,请重新输入计算机 成绩");
scanf("%f",&stu->computer);}
printf("请输入英语成绩(0~100):");
scanf("%f",&stu->english);
while(stu->englishenglish>100)
{getchar();
printf("输入错误,请重新输入英语成绩");
scanf("%f",&stu->english);}
printf("请输入数学成绩(0~100):");
scanf("%f",&stu->math);
while(stu->mathmath>100)
{getchar();
printf("输入错误,请重新输入数学成绩");
scanf("%f",&stu->math);}
p1=head;
p0=stu;
if(head==NULL)
{head=p0;p0->next=NULL;}/*当原来链表为空时,从首结点开始存放资料*/
else
{
if(p1->next==NULL)
{
p1->next=p0;
p0->next=NULL;
}
else
{
while(p1->next!=NULL)
{
p2=p1;p1=p1->next;
}
p1->next=p0;
p0->next=NULL;
}
}
n=n+1;
p1=head;
p0=stu;
for(i=1;i<n;i++)
{
for(j=i+1;j<=n;j++)
{
max=p1;
p1=p1->next;
if(max->number>p1->number)
{
k=max->number;
max->number=p1->number;
p1->number=k;
strcpy(t,max->name);
strcpy(max->name,p1->name);
strcpy(p1->name,t);/*交换前后结点中的姓名,使之与学号相匹配*/
fen=max->computer;
max->computer=p1->computer;
p1->computer=fen;
fen=max->english;
max->english=p1->english;
p1->english=fen;
fen=max->math;
max->math=p1->math;
p1->math=fen;
}
}
max=head;p1=head;
} end2:
printf("现在的学生数为:%d个!\n",n);
return(head);
}
score *search(score *head)
/*函数search,功能:查询学生成绩*/
{int number;
score *p1,*p2;
printf("输入要查询的学生的学号,");
scanf("%d",&number);
while(number!=0)
{
if(head==NULL)
{printf("\n没有任何学生资料!\n");return(head);}
printf("-----------------------------------------\n");
printf("|学号\t|姓名\t|计算机\t|英语\t|数学\t|\n");
printf("-----------------------------------------\n");
p1=head;
while(number!=p1->number&&p1->next!=NULL)
{p2=p1;p1=p1->next;}
if(number==p1->number)
{printf("|%d\t|%s\t|%.1f\t|%.1f\t|%.1f\t|\n",p1->number,p1->name,p1->computer,p1->english,p1->math);
printf("-----------------------------------------\n");}
else
printf("%d不存在此学生!\n",number);
printf("输入要查询的学生的学号,");
scanf("%d",&number);
}
printf("已经退出了!\n");
return(head);}
/*==============================================================================================*/
score *del(score *head)/*函数del,功能:删除学生资料*/
{
score *p1,*p2;
int number;
printf("输入要删除的学生的学号(输入0时退出):");
scanf("%d",&number);
getchar();
while(number!=0)/*输入学号为0时退出*/
{
if(head==NULL)
{
printf("\n没有任何学生资料!\n");
return(head);
}
p1=head;
while(number!=p1->number&&p1->next!=NULL)
{
p2=p1;p1=p1->next;
}
if(number==p1->number)
{
if(p1==head)
head=p1->next;
/*若p1指向的是首结点,把地二个结点地址赋予head*/
else
p2->next=p1->next;
printf("删除:%d\n",number);n=n-1;
}
else
printf("%d不存在此学生!\n",number);
printf("输入要删除的学生的学号:");
scanf("%d",&number);
getchar();
}
#ifdef DEBUG
printf("已经退出了!\n");
#endif
printf("现在的学生数为:%d个!\n",n);
return(head);
}
/*==============================================================================================*/
void print(score *head)/*函数print,功能:显示学生成绩*/
{
score *p;
if(head==NULL)
{printf("\n没有任何学生资料!\n");}
else
{printf("%d\n",n);
printf("-----------------------------------------\n");
printf("|学号\t|姓名\t|计算机\t|英语\t|数学\t|\n");
printf("-----------------------------------------\n");
p=head;
do
{printf("|%d\t|%s\t|%.1f\t|%.1f\t|%.1f\t|\n",p->number,p->name,p->computer,p->english,p->math);
printf("-----------------------------------------\n");
p=p->next;}while (p!=NULL);
}
}
/*==============================================================================================*/
score *tongji(score *head)
/*函数tongji,功能:统计学生成绩*/
{
float sum1=0,sum2=0,sum3=0,ave1=0,ave2=0,ave3=0,max=0,min;
score *p;
int x,y=0,i=0;
p=head;
printf("1个人总分和平均分\t2单科平均分\t3总分最高分\t4总分最低分\n");
scanf("%d",&x);
getchar();
switch(x)
{
case 1: if(head==NULL)
{printf("\n没有任何学生资料!\n");return(head);}
else
{
printf("---------------------------------------------------------\n");
printf("|学号\t|姓名\t|计算机\t|英语\t|数学\t|总分\t|平均分\t|\n");
printf("---------------------------------------------------------\n");
while(p!=NULL)
{
sum1=p->computer+p->english+p->math;
ave1=sum1/3;
printf("|%d\t|%s\t|%.1f\t|%.1f\t|%.1f\t|%.1f\t|%.1f\t|\n",p->number,p->name,p->computer,p->english,p->math,sum1,ave1);
printf("---------------------------------------------------------\n");/*打印表格域*/
p=p->next;}
}
return(head); break;
case 2: if(head==NULL)
{printf("\n没有任何学生资料!\n");return(head);}
while(p!=NULL)
{
sum1=sum1+p->computer;
sum2=sum2+p->english;
sum3=sum3+p->math;/*计算总分*/
y=y+1;
ave1=sum1/y;
ave2=sum2/y;
ave3=sum3/y;
p=p->next;
}
printf("计算机 平均分是%.1f\n",ave1);
printf("英语平均分是%.1f\n",ave2);
printf("数学平均分是%.1f\n",ave3);
return(head); break;
case 3:
if(head==NULL)
{printf("\n没有任何学生资料!\n");return(head);}
max=p->computer+p->english+p->math;
while(i<n)
{
i=i+1;
sum1=p->computer+p->english+p->math;
if(max<sum1)
max=sum1;
p=p->next;
}
printf("总分最高分:%.1f",max);
printf("\n");
return(head); break;
case 4: if(head==NULL)
{printf("\n没有任何学生资料!\n");return(head);}
while(p!=NULL)
{
min=p->computer+p->english+p->math;
while(p!=NULL)
{sum2=p->computer+p->english+p->math;
if(min>sum2)
min=sum2;
p=p->next;
}
}
printf("总分最低分:%.1f",min);
printf("\n");
return(head); break;
default :printf("输入错误,请重试!\n");
}
return(head);
}
/*==============================================================================================*/
save(score *p1)
/*函数save,功能:保存学生的资料*/
{
FILE *fp;
char filepn[20];/*用来存放文件保存路径以及文件名*/
printf("请输入文件路径及文件名:");
scanf("%s",filepn);
if((fp=fopen(filepn,"w+"))==NULL)
{
printf("不能打开文件!\n");
return 0;
}
fprintf(fp,"|学号\t|姓名\t|计算机\t|英语\t|数学\t|\n");
fprintf(fp,"-----------------------------------------\n");
while(p1!=NULL)
{
fprintf(fp,"%d\t%s\t%.1f\t%.1f\t%.1f\t\n",p1->number,p1->name,p1->computer,p1->english,p1->math);
p1=p1->next;
}
fclose(fp);
printf("文件已经保存!\n");
return 0;
}
/*==============================================================================================*/
score *paixu(score *head) /*定义排序函数。此函数带回一个指向链表头的指针*/
{ score *p,*max;
int i,j,x;
float fen;
char t[10];
if(head==NULL)
{printf("\n没有任何学生资料,请先建立链表!\n");return(head);}/*链表为空*/
max=p=head;
for(i=0;i<80;i++)
printf("*");
printf("1按学生学号排序\t2按学生姓名排序\t3按计算机 成绩排序\n");
printf("4按英语成绩排序\t5按数学成绩排序\t\n");
for(i=0;i<80;i++)
printf("*");
printf("请选择操作:");
scanf("%d",&x);/*选择操作*/
getchar();
switch(x)
{case 1 :
for(i=1;i<n;i++)
{
for(j=i+1;j<=n;j++)
{
max=p;
p=p->next;
if(max->number>p->number)
{
k=max->number;
max->number=p->number;
p->number=k;
strcpy(t,max->name);
strcpy(max->name,p->name);
strcpy(p->name,t);
fen=max->computer;
max->computer=p->computer;
p->computer=fen;
fen=max->english;
max->english=p->english;
p->english=fen;
fen=max->math;
max->math=p->math;
p->math=fen;
}
}
max=head;p=head;/*重新使max,p指向链表头*/
}
print(head);break;
case 2 : for(i=1;i<n;i++)
{
for(j=i+1;j<=n;j++)
{
max=p;
p=p->next;
if(strcmp(max->name,p->name)>0)/*字符串比较*/
{
strcpy(t,max->name);/*字符串复制*/
strcpy(max->name,p->name);
strcpy(p->name,t);
k=max->number;
max->number=p->number;
p->number=k;
fen=max->computer;
max->computer=p->computer;
p->computer=fen;
fen=max->english;
max->english=p->english;
p->english=fen;
fen=max->math;
max->math=p->math;
p->math=fen;
/*交换前后结点中的数学成绩,使之与姓名相匹配*/
}
}
p=head;
max=head;
}
print(head);
break;
case 3 : for(i=1;i<n;i++)
{for(j=i+1;j<=n;j++)
{max=p;
p=p->next;
if(max->computer>p->computer)
{
fen=max->computer;
max->computer=p->computer;
p->computer=fen;
k=max->number;
max->number=p->number;
p->number=k;
strcpy(t,max->name);
strcpy(max->name,p->name);
strcpy(p->name,t);
fen=max->english;
max->english=p->english;
p->english=fen;
fen=max->math;
max->math=p->math;
p->math=fen;
}
}
p=head;
max=head;
}
print(head);
break;
case 4 : for(i=1;i<n;i++)
{for(j=i+1;j<=n;j++)
{max=p;
p=p->next;
if(max->english>p->english)
{
fen=max->english;
max->english=p->english;
p->english=fen;
k=max->number;
max->number=p->number;
p->number=k;
strcpy(t,max->name);
strcpy(max->name,p->name);
strcpy(p->name,t);
fen=max->computer;
max->computer=p->computer;
p->computer=fen;
fen=max->math;
max->math=p->math;
p->math=fen;
}
}
p=head;
max=head;
}
print(head);
break;
case 5 : for(i=1;i<n;i++)
{for(j=i+1;j<=n;j++)
{max=p;
p=p->next;
if(max->math>p->math)
{
fen=max->math;
max->math=p->math;
p->math=fen;
k=max->number;
max->number=p->number;
p->number=k;
strcpy(t,max->name);
strcpy(max->name,p->name);
strcpy(p->name,t);
fen=max->computer;
max->computer=p->computer;
p->computer=fen;
fen=max->english;
max->english=p->english;
p->english=fen;
}
}
p=head;
max=head;
}
print(head);
break;
default :printf("输入错误,请重试! \n");
}
return (0);}
/*==============================================================================================*/
int menu(k)/*函数menu,功能:菜单选择界面*/
{
int i;
printf("\t\t\t\t学生信息管理系统\n");
for(i=0;i<80;i++)
printf("*");
printf(" \t\t\t1添加学生记录\t\t\t \n");
printf(" \t\t\t2.显示学生记录\t\t\t \n");
printf(" \t\t\t3.删除学生记录\t\t\t \n");
printf(" \t\t\t4.查询学生记录\t\t\t \n");
printf(" \t\t\t5.统计学生记录\t\t\t \n");
printf(" \t\t\t6.排序\t\t\t \n");
printf(" \t\t\t7.保存学生记录\t\t\t \n");
/*菜单选择界面*/
for(i=0;i<80;i++)
printf("*");
printf("请选择您所要的操作(选择(0)退出):");
scanf("%d",&k);/*选择操作*/
getchar();
return (k);}
main()
{score *head=0,*stu=0;
while(1)
{k=menu(k);
switch(k)/*用switch语句实现功能选择*/
{case 1: head=creat();break;/*调用创建链表函数*/
case 2: print(head); break;/*调用显示学生信息函数*/
case 3: head=del(head); break;/*调用删除学生信息函数*/
case 4: head=search(head);break;/*调用成绩查询函数*/
case 5: tongji(head); break;/*调用统计函数*/
case 6: paixu(head);break;/*调用排序函数*/
case 7: save(head);break;/*调用保存函数*/
case 0: exit(0);/*退出系统,返回主界面*/
default: printf("输入错误,请重试!\n"); }
}
自己套了修改!
4. 《面向对象程序设计》课程设计报告,好心人帮帮忙,要求做一个系统,我只要源代码和系统类图
《面向对象程序设计》课程设计报告我们有完整的.
5. 求个学生成绩管理系统的面向对象C++的程序代码
。。。你这是坑啊,网上随便一搜就有啊,最主要是,这个真心是给你总结的机会,就是把你以前学的综合起来,你试试自己做吧,慢慢做,绝对能出来的。只是总结技术的机会
6. 【100分】求一个面向对象的实际项目源代码,大家踊跃发言
我给两个例子,不是复制粘贴的,自己曾经写过的
工资管理系统
//cpp
#include
#include
using namespace std;
class Employee
{//定义Employee类
protected:
string name,number;
public:
Employee(){};//构造函数
virtual void show()//显示姓名与编号的虚函数
{
cout<<"姓名:"<<name<<endl;
cout<<"编号:"<<number<<endl;
}
~Employee(){}//析构函数
};
class Manager:public Employee
{//定义Manager类,公有继承Employee类
private:
double salary;
public:
static int m;
Manager(){};//构造函数
void show()//显示经理详细情况函数
{
cout<<"姓名:"<<name<<endl;
cout<<"编号:"<<number<<endl;
cout<<"月工资:"<<salary<<endl;
}
Manager &operator=(const Manager &);//声明重载赋值函数
void put(string na,string nu,double sa)//给成员赋值函数
{
name=na;
number=nu;
salary=sa;
}
};
Manager &Manager::operator=(const Manager &p)//定义重载赋值函数
{
name=p.name;
number=p.number;
salary=p.salary;
return *this;
}
class HourlyWorker:public Employee
{//定义HourlyWorker类,公有继承Employee类
private:
double hour,wage;
public:
static int n;
HourlyWorker(){};//构造函数
void show()//显示钟点工详细情况函数
{
cout<<"姓名:"<<name<<endl;
cout<<"编号:"<<number<<endl;
cout<<"小时工资:"<<wage<<endl;
cout<<"月工作小时:"<<hour<<endl;
}
HourlyWorker &operator=(const HourlyWorker &);//声明重载赋值函数
void put(string na,string nu,double ho,double wa)//给成员赋值函数
{
name=na;
number=nu;
hour=ho;
wage=wa;
}
};
HourlyWorker &HourlyWorker::operator=(const HourlyWorker &p)//定义重载赋值函数
{
name=p.name;
number=p.number;
hour=p.hour;
wage=p.wage;
return *this;
}
int HourlyWorker::n=0;
int Manager::m=0;
void main()
{
Manager x[5];//建立5个Manager类
HourlyWorker y[5];//建立5个HourlyWorker类
int i;
string name,number,sort;
double wage,hour,salary;
bool flags=true;
while(flags)
{
cout<<"[1]增加一个职工"<<endl;
cout<<"[2]显示数组中所有的职工以及他们的工资"<<endl;
cout<<"[3]显示数组中所有的经理以及他们的工资"<<endl;
cout<<"[4]显示数组中钟点工以及他们的工资"<<endl;
cout<<"[5]退出"<<endl;
int num;
cin>>num;
switch(num)
{
case 1:
cout<<"输入职工信息:"<<endl<<"姓名:";
cin>>name;
cout<<"编号:";
cin>>number;
cout<<"类别:(输入“经理”或“钟点工”)";
cin>>sort;
if(sort=="经理")
{
cout<<"月工资:";
cin>>salary;
Manager::m++;
x[Manager::m-1].put(name,number,salary);
cout<<"***增加一个职工***"<<endl;
x[Manager::m-1].show();
}
else if(sort=="钟点工")
{
cout<<"小时工资:";
cin>>wage;
cout<<"月工作小时数:";
cin>>hour;
HourlyWorker::n++;
y[HourlyWorker::n-1].put(name,number,hour,wage);
cout<<"***增加一个职工***"<<endl;
y[HourlyWorker::n-1].show();
}
else cout<<"输入有误,请重新输入!"<<endl;
break;
case 2:
cout<<"***职工工资表***"<<endl;
for(i=0;i<Manager::m;i++)
x[i].show();
for(i=0;i<HourlyWorker::n;i++)
y[i].show();
break;
case 3:
cout<<"***经理工资表***"<<endl;
for(i=0;i<Manager::m;i++)
x[i].show();
break;
case 4:
cout<<"***钟点工工资表***"<<endl;
for(i=0;i<HourlyWorker::n;i++)
y[i].show();
break;
case 5:flags=false;
exit(0);
}
}
}
面向对象实例6
#include
#include
class xy;
//**********************************************
//*********************ra类*********************
//**********************************************
class ra
{
public:
double r,a;
ra(double rr=20,double aa=10){r=rr;a=aa;}//ra构造函数
ra(const ra &p){r=p.r;a=p.a;}//ra拷贝构造函数
friend istream &operator>>(istream &in,ra &ob);//ra">>"
friend ostream &operator<<(ostream &out,ra &ob);//ra"<<"
operator double(){return r;}//double转换
operator xy();//xy类转换,函数体必须放到类外面
};
istream &operator>>(istream &in,ra &ob)//ra">>"
{
cout<<"输入r、a的值:"<<endl;
cout<<"r:";
in>>ob.r;
cout<<"a:";
in>>ob.a;
return in;
}
ostream &operator<<(ostream &out,ra &ob)//ra"<<"
{
cout<<"r=";
out<<ob.r;
cout<<",a=";
out<<ob.a;
return out;
}
//**********************************************
//*********************xy类*********************
//**********************************************
class xy
{
public:
double x,y;
xy(double xx=20,double yy=10){x=xx;y=yy;}//xy构造函数
xy(const xy &p){x=p.x;y=p.y;}//xy拷贝构造函数
friend istream &operator>>(istream &in,xy &ob);//xy">>"
friend ostream &operator<<(ostream &out,xy &ob);//xy"<<"
operator int(){return int(x);}//int转换
operator double(){return x;}//double转换
operator ra()//ra类转换
{
ra ra3;
ra3.r=sqrt(x*x+y*y);
ra3.a=atan(y/x);
return ra3;
}
double friend operator +(ra ra1,double d1);//友元函数xy"+"
double operator +(double d1)//成员函数xy"+"
{
double d=x+d1+8;
return d;
}
double operator *(ra ra1)//成员函数xy"*"
{
double m=x*double(ra1);
return m;
}
};
istream &operator>>(istream &in,xy &ob)//xy">>"
{
cout<<"输入x、y的值:"<<endl;
cout<<"x:";
in>>ob.x;
cout<<"y:";
in>>ob.y;
return in;
}
ostream &operator<<(ostream &out,xy &ob)//xy"<<"
{
cout<<"x=";
out<<ob.x;
cout<<",y=";
out<<ob.y;
return out;
}
double operator +(ra ra1,double d1)//友元函数xy"+"
{
double d=ra1.r+d1+5;
return d;
}
ra::operator xy()
{
xy xy3;
xy3.x=r*cos(a);
xy3.y=r*sin(a);
return xy3;
}
//**********************************************
//*********************主函数*******************
//**********************************************
void main()
{
ra ra_3=30;//系统类型转换为类类型
ra ra_31=ra(31);
xy xy_3=33;
xy xy_31=xy(31);
ra ra_4(40,44);//类类型转换为系统类型
double d1=ra_4;
double d11=double(ra_4);
xy xy_4(40.,48);
int i=xy_4;
double d2=xy_4;
xy xy_1(10,11);//xy与ra类的相互转换
ra ra_1;
ra_1=xy_1;
ra ra_2(20,22);
xy xy_2;
xy_2=ra_2;
xy xy_7;//系统类型与类类型的运算
ra ra_7(60,66);
xy_7=ra_7+3.4;
xy xy_71;
xy_71=double(ra_7)+3.4;
xy xy_9(90,93),xy_10;//系统类型与类类型混合运算
ra ra_9(92,95),ra_10(101,104);
xy_10=xy_9*ra_9-5.6*ra_10+3.3;
xy_10=double(xy_9)*double(ra_9)-5.6*double(ra_10)+3.3;
}
7. 求一个PHP面向对象的实例源代码
http://bbs.php100.com/read-htm-tid-26523.html
8. 【100分】求一个面向对象的实际项目源代码,大家踊跃发言
一、建议:
1、既然自己认为OOP理论性太强,就没有必要直接要2000行左右的代码了,那样估计你会看得很烦;
2、既然是想应用抽象类和接口等概念,我建议你最好先理解它们;
3、如果实在是想要实际项目的源代码的话,我建议你可以到www.laohu.net网站下载;
二、抽象类和接口的实例与讲解
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
namespace AppTest
{
class Demo_abstract
{
static void Main(string[] args)
{
double len = 2.5;
double wid = 3.0;
double rad = 4.1;
Rectangle aRect = new Rectangle();
aRect.length = len;
aRect.width = wid;
Circle aCirc = new Circle(rad);
Console.WriteLine("Area of Rect is:{0}", aRect.Area());
Console.WriteLine("Area of Circ is:{0}", aCirc.Area());
//体现 abstract 的优势,不用的实例获取不同的功能
//结果与 Rectangle实例的一样
Shape shape = new Rectangle(len, wid);
Console.WriteLine("Area of shape is:{0}", shape.Area());
Thread.Sleep(3 * 1000); //暂停3秒看结果
}
}
//图形
abstract class Shape //抽象基类,不可实例化
{
public const double pi = 3.14; //常量
protected double x, y; //私有,可继承变量
public Shape() //默认构造函数
{
x = y = 0;
}
public Shape(double x, double y) //带参数构造函数
{
this.x = x;
this.y = y;
}
public abstract double Area(); //抽象方法,需重载
}
//方形
class Rectangle : Shape
{
public Rectangle() : base() { }
public Rectangle(double x, double y) : base(x, y) { }//使用基类构造函数
public override double Area() //函数重载
{
return (x * y);
}
public double length //属性:矩形长度
{
get
{
return x;
}
set
{
if (value > 0) { x = value; }
}
}
public double width //属性:矩形宽度
{
get
{
return y;
}
set
{
if (value > 0) { y = value; }
}
}
}
//椭圆
class Ellipse : Shape
{
public Ellipse(double x, double y) : base(x, y) { }//使用基类Shape的构造函数
public override double Area() //函数重载
{
return pi * x * y;
}
}
//圆形
class Circle : Ellipse
{
public Circle(double r) : base(r, 0) { } //使用基类Ellipse的构造函数
public override double Area() //函数重载
{
return pi * x * x;
}
}
}