#define PI 3.14
class table
{
public:
double heigh
char *color
public:
virtual void display()=0//写成纯虚函数便于重载
}
class circle
{
public:
double radius//半径
public:
virtual void display()=0//写成纯虚函数便于重载
}
class roundtable : public table,public circle
{
public:
void iniroundtable(double h,double r,char *c)
{
heigh=h
radius=r
color=c
}
void display()
{
cout<<"the heigh of the round table is "<<heigh<<endl
cout<<"the color of the round table is "<<color<<endl
cout<<"the area of the round table is "<<PI*radius*radius<<endl
}
protected:
double heigh,radius
char *color
}
int main()
{
roundtable t1
t1.iniroundtable(1,2,"red")
t1.display()
return 0
}
简单点,能用,还想加些什么就很简单了。
1、约瑟夫问题:Joseph问题的一种描述是:编号为1、2、……、n的n个人按顺时针方向围坐一圈,每人持有一个密码(正整数)。一开始任选一个正整数作为报数上限值m,从第一个人开始顺时针方向自1开始顺序报数,报到m时停止报数,报m的人出列,将他的密码作为新的m值,从他在顺时针方向的下一个人开始重新从1报数,如此下去,直至所有人全部出列为止。
2、例程:
#include <stdio.h>#include <stdlib.h>
typedef int ElemType
typedef struct LNode{
ElemType dataint num
struct LNode *next
}LNode,*LinkList
void CreateList_L(LinkList *L,int n)
{ int i=0
ElemType e
LinkList p,q
*L=(LinkList)malloc(sizeof(LNode))
(*L)-> next=NULL(*L)-> data=n
q=*L
while(i <n)
{ scanf("%d",&e)
p=(LinkList)malloc(sizeof(LNode))
p-> data=ep-> num=i+1
p-> next=NULL
q-> next=p
q=p
i++
}
p-> next=(*L)-> next
}
void PrintList(LinkList L)
{ int i=0
LinkList p
p=L-> next
while(i <L-> data)
{
printf("%5d",p-> data)
p=p-> next
i++
}
printf("\n")
}
void Put(LinkList *L)
{ int i,mLinkList p,q
printf("input a number:\n")
scanf("%d",&m)
q=(*L)-> next
while((*L)-> data)
{for(i=0i <m-1i++)
{p=q
q=q-> next
}
printf("%5d",q-> num)
m=q-> data
p-> next=q-> next
free(q)
q=p-> next
(*L)-> data=(*L)-> data-1
}
}
void main()
{LinkList L
int a
printf("请输入人数:")
scanf("%d",&a)
printf("请输入密码:")
CreateList_L(&L,a)
printf("您输入的数字为:\n")
PrintList(L)
Put(&L)
}