| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 352 人关注过本帖
标题:求为什么?运行不完呢?
取消只看楼主 加入收藏
duotianshi
Rank: 2
等 级:论坛游民
帖 子:7
专家分:13
注 册:2012-11-10
结帖率:0
收藏
已结贴  问题点数:20 回复次数:3 
求为什么?运行不完呢?
#pragma once
#include"set.h"
#include<iostream>
using namespace std;
Set::Set()
{
    set=new int[20];
    size=0;
    key=0;
}
void Set::AddSet(int n)
{
    if(size<20)
    {
        set[size++]=n;
        key=1;
    }
    else {cout<<"The Set is full!\n";}
}
void Set::DelSet(int n)
{
    int d,m=0;
    if(!key)
        cout<<"The Set is empty!\n";
    else
    {
        for(d=0;d<size;d++)
        {
            if(set[d]==n)
            {
                for( m=d;m<size;m++)
                    set[m]=set[m+1];
                size--;
                if(size==0)
                    key=0;
                break;
            }
        }
        if(!m)
        {
            cout<<"No,wrong number!Please do it again!\n";
        }
    }
}
void Set::OutSet()
{
    int i;
    for(i=0;i<size;i++)
        cout<<set[i]<<"  ";
    cout<<endl;
}
int Set::Getsize()
{
    return size;
}
int Set::Getnumber(int n)
{
    return set[n];
}
Set::~Set()
{
    delete[] set;
}
#include"string"
using namespace std;
class Set{
public:
    Set();
    void AddSet(int n);
    void DelSet(int n);
    void OutSet();
    int Getnumber(int n);
    int Getsize();
    ~Set();
private:
    int *set;
    int key;
    int size;
};
#pragma once

#include"set.h"

#include<iostream>
#include<cstdlib>

using namespace std;


void Operates1(Set &s1,Set s2);
void Operates2(Set &s2,Set s1);
void Relation(Set s1,Set s2);
void Jiaoji(Set s1,Set s2);
void Bingji(Set s1,Set s2);
void Chaji(Set s1,Set s2);

void main()
{
    Set s1,s2;
    Operates1(s1,s2);
   
}

void Operates1(Set &s1,Set s2)
{
    int i,m;
    while(1)
    {
        cout<<"Make your choice: 1:AddSet  2:DelSet   3:OutSet 4:Operate s2 5:Relation 0:exit\n";
        cin>>i;
        switch(i)
        {
        case 1:cout<<"The number is:";cin>>m;s1.AddSet(m);break;
        case 2:cout<<"The number is:";cin>>m;s1.DelSet(m);break;
        case 3:cout<<"The Set is:";s1.OutSet();break;
        case 4:Operates2(s2,s1);break;
        case 5:Relation(s1,s2);break;
        case 0:exit(0);
        default:printf("No,the number is wrong!Please do it again!\n");
        }
    }
}
void Operates2(Set &s2,Set s1)
{
    int i,m;
    while(1)
    {
        cout<<"Make your choice: 1:AddSet  2:DelSet   3:OutSet 4:Operate s1 5:Relation 0:exit\n";
        cin>>i;
        switch(i)
        {
        case 1:cout<<"The number is:";cin>>m;s2.AddSet(m);break;
        case 2:cout<<"The number is:";cin>>m;s2.DelSet(m);break;
        case 3:cout<<"The Set is:";s2.OutSet();break;
        case 4:Operates1(s1,s2);break;
        case 5:Relation(s1,s2);break;
        case 0:exit(0);
        default:printf("No,the number is wrong!Please do it again!\n");
        }
    }
}
void Relation(Set s1,Set s2)
{
    int i;
    while(1)
    {
        cout<<"Make your choice: 1:Jiaoji 2:Bingji 3:Chaji 0:exit:";cin>>i;
        switch(i)
        {
        case 1:Jiaoji(s1,s2);break;
        case 2:Bingji(s1,s2);break;
        case 3:Chaji(s1,s2);break;
        case 0:exit(0);
        default:printf("No,the number is wrong!Please do it again!\n");
        }
    }
}
void Jiaoji(Set s1,Set s2)
{
    int m,n;
    for(m=0;m<s1.Getsize();m++)
        for(n=0;n<s2.Getsize();n++)
            if(s1.Getnumber(m)==s2.Getnumber(n))
            {
                cout<<s1.Getnumber(m)<<" ";
                break;
            }
    cout<<endl;
}
void Bingji(Set s1,Set s2)
{
    int m,n,i=0,s;
    int all[40],less[20];
    for(m=0;m<s1.Getsize();m++)
        for(n=0;n<s2.Getsize();n++)
            if(s1.Getnumber(m)==s2.Getnumber(n))
                less[i++]=s1.Getnumber(m);
    for(m=0;m<s1.Getsize();m++)
        all[m]=s1.Getnumber(m);
    for(n=0;n<s2.Getsize();n++)
        all[m+n]=s2.Getnumber(n);
    s=s1.Getsize()+s2.Getsize();
    //cout<<s;
    for(m=0;m<s;m++)
        for(n=0;n<i;n++)
        {
            if(all[m]==less[n])
                break;
            else
                if(n==i-1)
                    cout<<all[m]<<" ";
        }
    for(m=0;m<i;m++)
        cout<<less[m]<<" ";
    cout<<endl;
}
void Chaji(Set s1,Set s2)
{
    int m,n,i=0,s;
    int all[40],less[20];
    for(m=0;m<s1.Getsize();m++)
        for(n=0;n<s2.Getsize();n++)
            if(s1.Getnumber(m)==s2.Getnumber(n))
                less[i++]=s1.Getnumber(m);
    for(m=0;m<s1.Getsize();m++)
        all[m]=s1.Getnumber(m);
    for(n=0;n<s2.Getsize();n++)
        all[m+n]=s2.Getnumber(n);
    s=s1.Getsize()+s2.Getsize();
    cout<<s;
    for(m=0;m<s;m++)
        for(n=0;n<i;n++)
        {
            if(all[m]==less[n])
                break;
            else
                if(n==i-1)
                    cout<<all[m]<<" ";
        }
    for(m=0;m<i;m++)
        cout<<less[m]<<" ";
    cout<<endl;
}
搜索更多相关主题的帖子: void include 
2012-11-10 11:32
duotianshi
Rank: 2
等 级:论坛游民
帖 子:7
专家分:13
注 册:2012-11-10
收藏
得分:0 
呵呵,不是,我仔细思考了的,自是我刚加进来,还不熟悉这里的规则,呵呵,还望见谅啊
2012-11-14 22:11
duotianshi
Rank: 2
等 级:论坛游民
帖 子:7
专家分:13
注 册:2012-11-10
收藏
得分:0 
恩,就是函数运行到输出他的并集或者交集的时候运行不完了,好像是系统没有给她分配空间一样!!!
2012-11-14 22:13
duotianshi
Rank: 2
等 级:论坛游民
帖 子:7
专家分:13
注 册:2012-11-10
收藏
得分:0 
这是一个求一个集合的并集,交集的程序,那个帮帮忙哈,谢谢了!!!
2012-11-14 22:17
快速回复:求为什么?运行不完呢?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.060932 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved