| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 732 人关注过本帖
标题:那位好心人帮忙给我写写这个程序的主函数
只看楼主 加入收藏
快乐小车车
Rank: 1
等 级:新手上路
帖 子:10
专家分:3
注 册:2012-2-29
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:3 
那位好心人帮忙给我写写这个程序的主函数
#include<iostream.h>
template <class T>
class LinearList
{
public:
    virtual bool IsEmpty() const=0;
    virtual int Length() const=0;
    virtual bool Find(int i,T& x) const=0;
    virtual int Search(T x) const=0;
    virtual bool Insert(int i,T x)=0;
    virtual bool Delete(int i)=0;
    virtual bool Update(int i,T x)=0;
    virtual void Output(ostream& out)const=0;
protected:
    int n;
};
#include"Linearlist.h"
template <class T>
class SequList:public LinearList<t>
{
    public:
        SeqList(int mSize);
        ~SeqList(){delete [] element;}
        bool IsEmpty() const;
        int Length() const;
        bool Find(int i,T& x) const;
        int Search(T x) constSearch(T x) const;
        bool Insert(int i,T x);
        bool Delete(int i);
        bool Update(int i,T x);
        void Output(ostream& out)const;
    private:
        int maxLength;
        T *elements;
};
template <class T>
SequList<T>::SequList(int mSize)
{
    maxLength=mSize;
    elements=new T[maxLength];
    n=0;

}
template <class T>
bool SequList <T>::IsEmpty() const
{
    return n==0;
}
template <class T>
int SeqList<T>::Length() const
{
    return 0;
}
template <class T>
bool SeqList<T>::Find(int i,T& x) const
{
    if(i<0||i>n-1)
    {
        cout<<"out of Bounds"<<endl;
        return false;
    }
    x=elements[i];
    return true;
}
template <class T>
int SeqList<T>::Search(T x) const
{
    for(int j=0;j<n;j++)
        if(elements[j]==x)
            return j;
        return -1;
}
template <class T>
bool SeqList<T>::Insert(int i,T x)
{
    if(i<-1||i>n-1)
    {
        cout<<"out of Bounds"<<endl;
        return false;
    }
    if(n==maxLength)
    {
        cout<<"OverFlow"<<endl;
        return false;
    }
    for(int j=n-1;j>i;j--)
        elements[j+1]=elements[j];
    elemets[i+1]=x;
    n++;
    return true;
}
template <class T>
bool SeqList<T>::Delete(int i)
{
    if(!n)
    {
       cout<<"UnderFlow"<<endl;
        return false;
    }
    if(i<0||i>n-1)
    {
        cout<<"out of Bounds"<<endl;
        return false;
    }
    for(int j=i+1;j<n;j++)
        elements[j-1]=elements[j];
    n--;
    return true;
}
template <class T>
bool SeqList<T>::Update(int i,T x)
{
    if(i<0||i>n-1)
    {
        cout<<"out of Bounds"<<endl;
        return false;
    }
    elements[i]=x;
    return true;
}
template <class T>
void SeqList<T>::Output(ostream& out)const
{
    for(int i=0;i<n;i++)
        out<<elements[i]<<' ';
    out<<endl;
}
搜索更多相关主题的帖子: class 函数 include public 
2012-03-26 21:42
lhb62232397
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:1
帖 子:117
专家分:546
注 册:2011-11-6
收藏
得分:7 
你这个好像不是c#吧,这个论坛是个c#论坛,估计除非是高手才能解决。你可以尝试进入c或c++论坛
2012-03-27 14:13
lcawen
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:41
专家分:184
注 册:2011-8-11
收藏
得分:7 
//已调试成功
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication9
{
    class Program
    {
        static void Main(string[] args)
        {
            //创建一个Dictionary<TKey, TValue>类
            Dictionary<int, City> add = new Dictionary<int, City>();


            //实例化四个城市类对象
            City city1 = new City("仙桃市", 0728);
            City city2 = new City("黄石市", 0714);
            City city3 = new City("荆州市", 0716);
            City city4 = new City("襄樊市", 0710);

            City city5 = new City();
            //city5._City = "黄冈市";
            //city5._Number = 0713;

            //将四个学生类对象添加到泛型集合类中
            add.Add(city1._Number, city1);
            add.Add(city2._Number, city2);
            add.Add(city3._Number, city3);
            add.Add(city4._Number, city4);

            string choice;
            do
            {
                Console.WriteLine("********************************");
                Console.WriteLine("******* 1.显示全部信息 *********");
                Console.WriteLine("******* 2.增加         ********");
                Console.WriteLine("******* 3.删除         ********");
                Console.WriteLine("******* 4.查询         *********");
                Console.WriteLine("******* 5.修改         ********");
                Console.WriteLine("******* 6.退出         ********");
                Console.WriteLine("*******************************");

                choice = Console.ReadLine();//功能选项

                switch (choice)
                {
                    case "1":
                        Console.WriteLine("全部城市信息为:");
                        //打印输出全部信息
                        foreach (City c in add.Values)
                        {
                            Console.WriteLine(c.ToString());
                        }
                        break;
                    case "2":
                        Console.WriteLine("请输入要添加的城市区号:");
                        city5._Number = Convert.ToInt32(Console.ReadLine());//接受用户输入区号
                        Console.WriteLine("请输入要添加的城市名称:");
                        city5._City = Console.ReadLine();//接受用户输入城市
                        add.Add(city5._Number, city5);//将输入的
                        Console.WriteLine("已成功添加信息");
                        break;
                    case "3":
                        Console.WriteLine("请输入要删除的城市区号:");
                        int qh = Convert.ToInt32(Console.ReadLine());
                        add.Remove(qh);
                        Console.WriteLine("已成功删除信息。");
                        break;
                    case "4":
                        Console.WriteLine("请输入你要查询的城市区号:");
                        int str = Convert.ToInt32(Console.ReadLine());

                        if (add.ContainsKey(str))
                        {
                            Console.WriteLine(add[str].ToString());
                        }
                        else
                        {
                            Console.WriteLine("没有该城市的信息");
                        }
                        break;
                    case "5":
                        Console.WriteLine("请输入你要修改的城市区号:");
                        int qh1 = Convert.ToInt32(Console.ReadLine());
                        Console.WriteLine("{1}的区号{0}要修改", add[qh1]._Number, add[qh1]._City);
                        if (add.ContainsKey(qh1))
                        {
                            Console.WriteLine("修改的城市区号为:");
                            int str1 = Convert.ToInt32(Console.ReadLine());
                            string _city0 = add[qh1]._City;
                            add.Remove(qh1);
                            City city0 = new City(_city0, str1);
                            add.Add(str1, city0);
                            Console.WriteLine("{1}的区号修改为:{0}", add[str1]._Number, add[str1]._City);
                        }
                        break;
                    case "6":
                        break;
                    default:
                        Console.WriteLine("你输入的选项有误!");
                        break;
                }

            } while (choice != "6");
            if (choice == "6")
            {
                Console.WriteLine("已退出!!!");
            }

            Console.ReadKey();

        }
    }


    /// <summary>
    /// 城市类
    /// </summary>
    class City
    {
        private string city;//城市
        private int number;//区号


        //无参构造方法
        public City()
        {
        }

        //有参构造方法用于赋初值
        public City(string city, int number)
        {
            this.city = city;
            this.number = number;
        }

        public string _City
        {
            get { return city; }//只读
            set { this.city = value; }//只写
        }

        public int _Number
        {
            get { return number; }//只读
            set { this.number = value; }//只写
        }

        //重写系统自带的ToString()方法
        public override string ToString()
        {
            return city + "的区号为:" + number;
        }

    }

}
2012-03-30 11:42
zhoufeng1988
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:北京
等 级:贵宾
威 望:27
帖 子:1432
专家分:6329
注 册:2009-5-31
收藏
得分:7 
楼上发的素什么?

楼主的是一个C++线性表模板.main函数很简单撒~

程序代码:
#include "LinearList.h"

int main(int argc, char *argv[])
{
    LinearList<int> seqList;

    seqList.IsEmpty();
    // TODO
}
2012-03-30 23:51
快速回复:那位好心人帮忙给我写写这个程序的主函数
数据加载中...
 
   



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

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