找回密码
 注册
搜索
热搜: 回贴
  • 前程无忧官网首页 有什么好的平台可以
  • 最新的销售平台 互联网营销的平台有哪
  • 制作网页的基本流程 网页制作和网页设
  • 【帝国CMS】输出带序号的列表(数字排
  • 网站建设公司 三一,中联,极东泵车的
  • 织梦 建站 织梦网站模版后台怎么更改
  • 云服务官网 哪些网站有免费的简历模板
  • 如何建网站要什么条件 建网站要用什么
  • 吉林市移动公司电话 吉林省退休人员网
  • 设计类毕业论文 网站设计与实现毕业论
查看: 1146|回复: 9

新学C++,有个问题

[复制链接]
发表于 2009-11-3 23:46:41 | 显示全部楼层 |阅读模式 IP:江苏扬州
才开始看C++.照着书敲了一段程序.结果是"v' : undeclared identifier"说是有个错误.我不大懂.大哥帮帮忙吧.谢谢
程序:
#include<iostream>
using namespace std;
class ARR
{
    int m;
    int a[100];
public:
    ARR(int x[],int size)
    {
        m=size;
        for(int i=0;i<m;i++)
            a[i]=x[i];
    }
    void delsame();
    void show()
    {
        for(i=0;i<m;i++)
        {
            cout<<a[i]<<"\t";
            if((i+1)%5==0)
                cout<<edl;
        }
        cout<<endl;
    }
};
void ARR::delsame()
{
    int i,j;
    for(i=0;i<m-1;i++)
    {
        if(a[i]=a[i+1])
        {
            for(j=i+1;j<m-1;j++)
        {
            a[j]=a[j+1];
        }
        m--;
        i--;
        }
    }
}
int main()
{
    int b[16]={1,2,2,3,3,4,4,5,6,6,7,7,8,8,9,10,10}
    ARR v(b,sizeof(b)/sizeof(b[0]));
    v.show();
    v.delsame();
    v.show();
    return 0;
发表于 2009-11-3 23:46:43 | 显示全部楼层 IP:江苏扬州
好了有点小错
#include<iostream>
using namespace std;
class ARR
{
    int m;
    int a[100];
public:
    ARR(int x[],int size)
    {
        m=size;
        for(int i=0;i<m;i++)
            a[i]=x[i];
    }
    void delsame();
    void show()
    {
        for(int i=0;i<m;i++)
        {
            cout<<a[i]<<"\t";
            if((i+1)%5==0)
                cout<<endl;
        }
        cout<<endl;
    }
};
void ARR::delsame()
{
    int i,j;
    for(i=0;i<m-1;i++)
    {
        if(a[i]=a[i+1])
        {
            for(j=i+1;j<m-1;j++)
        {
            a[j]=a[j+1];
        }
        m--;
        i--;
        }
    }
}
int main()
{
    int b[20]={1,2,2,3,3,4,4,5,6,6,7,7,8,8,9,10,10};
    ARR v(b,sizeof(b)/sizeof(b[0]));
    v.show();
    v.delsame();
    v.show();
    return 0;
}
回复

使用道具 举报

发表于 2009-11-3 23:46:45 | 显示全部楼层 IP:江苏扬州
你改为这样就没问题了:
#include <iostream>
using namespace std;
class ARR
{
    int m;
    int a[100];
public:
    ARR(int x[], int size)
    {
        m = size;
        for(int i = 0; i < m; i++)
            a[i] = x[i];
    }
    void delsame();
    void show()
    {
        for(int i = 0; i < m; i++)
        {
            cout << a[i] << "\t";
            if((i + 1) % 5 == 0)
                cout << endl;
        }
        cout<<endl;
    }
};
void ARR::delsame()
{
    int i, j;
    for(i = 0; i < m - 1; i++)
    {
        if(a[i] = a[i + 1])
        {
            for(j = i + 1; j < m - 1;j++)
            {
                a[j] = a[j + 1];
            }
            m--;
            i--;
        }
    }
}
int main()
{
    int b[] = {1, 2, 2, 3, 3, 4, 4, 5, 6, 6, 7, 7, 8, 8, 9, 10, 10};
    ARR v(b, sizeof(b) / sizeof(b[0]));
    v.show();
    v.delsame();
    v.show();
    return 0;
}
回复

使用道具 举报

发表于 2009-11-3 23:46:46 | 显示全部楼层 IP:江苏扬州
提个意见,大家贴程序求助或者帮求助者修改程序,特别是整段整段的,最好注释一下,你改动了什么地方,别人的错的什么地方。

谢谢合作,o(∩_∩)o...
回复

使用道具 举报

发表于 2009-11-3 23:46:47 | 显示全部楼层 IP:江苏扬州
呵呵.知道了.太大意了
回复

使用道具 举报

发表于 2009-11-3 23:46:48 | 显示全部楼层 IP:江苏扬州
恩.同意.我对着程序查了半天才,找到的.不过,还是谢谢楼上的两位大哥了
回复

使用道具 举报

发表于 2009-11-3 23:46:50 | 显示全部楼层 IP:江苏扬州
谢谢斑竹的建议。。。不过我这个好像又没注意。。下次改。。。呵呵
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
template <class T>
class ARR
{
    int m;
    vector<T> vec ;
    vector<T>::iterator it;
public:
    ARR(T a[],int size)
    {
     vector<T> vec1(a,a+size);
     vec=vec1;
    }
    void delsame()
    {
        sort(vec.begin(),vec.end());
        it=unique(vec.begin(),vec.end());
        vec.erase(it,vec.end());
    }
    void show()
    {   
        for(vector<int>::iterator iter=vec.begin(); iter!=vec.end();iter++)
        {
            cout<<*iter<<"\t";            
        }
        cout<<endl;
    }
};

int main()
{
    int b[]={1,2,2,3,3,4,4,5,6,6,7,7,8,8,9,10,10};
    ARR<int> v(b,sizeof(b)/sizeof(b[0]));
    v.show();
    v.delsame();
    v.show();
    return 0;
}
回复

使用道具 举报

发表于 2009-11-3 23:46:54 | 显示全部楼层 IP:江苏扬州
不好意思.这个程序的目地是删除序列中的想同的数.但是结果没有把删除的结果显示出来啊
回复

使用道具 举报

发表于 2009-11-3 23:46:56 | 显示全部楼层 IP:江苏扬州
我的是把删除过后的结果显示出来。。结果是1。。。10
回复

使用道具 举报

发表于 2009-11-3 23:46:58 | 显示全部楼层 IP:江苏扬州
非常感谢
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )

GMT+8, 2024-9-30 19:31 , Processed in 0.373581 second(s), 13 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表