| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2130 人关注过本帖
标题:《观影网站影评信息管理系统》课设作业(编译运行都可以,就是结果不对,望 ...
只看楼主 加入收藏
krisdei
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2018-4-6
结帖率:50%
收藏
 问题点数:0 回复次数:2 
《观影网站影评信息管理系统》课设作业(编译运行都可以,就是结果不对,望大神赐教)
#include <iostream>
#include<string>
#include<time.h>
using namespace std;
#define CMAX 1024
const static int MAX=100;
class Base
{
public:
    int ID;
    string Name;
    virtual void Print()=0;
    virtual void Input()=0;
    virtual void Reset(string name)=0;
    virtual void Read(char *s)=0;
    virtual char* Save()=0;
};
class user:public Base
{
public:
    string username;//用户名
    string level;//等级
    string age;//年龄
    string occupation;//职业
    string hobby;//兴趣
    string email;//电子邮箱
    virtual void Print()
    {
        cout<<"ID:"<<ID<<" 用户名:"<<username<<" 等级: "<<level<<" 年龄:"<<age<<" 职业:"<<occupation<<" 兴趣:"<<hobby<<"电子邮箱:"<<email<<endl;
    }
    //返回类型名
    virtual void Input(){
        cout<<"输入用户名:";
        cin>>username;
        cout<<"输入等级:";
        cin>>level;
        cout<<"输入年龄:";
        cin>>age;
        cout<<"输入职业:";
        cin>>occupation;
        cout<<"输入兴趣:";
        cin>>hobby;
        cout<<"输入电子邮箱:";
        cin>>email;
    }
    virtual void Reset(string name)
    {
        Name=name;
        cout<<"用户名:";
        cin>>username;
        cout<<"输入等级:";
        cin>>level;
        cout<<"输入年龄:";
        cin>>age;
        cout<<"输入职业:";
        cin>>occupation;
        cout<<"输入兴趣:";
        cin>>hobby;
        cout<<"输入电子邮箱:";
        cin>>email;
    }
    virtual void Read(char *s){
        char a[8][CMAX];
        sscanf(s,"%d %s %s %s %s %s %s %s %s",&ID,a[0],a[1],a[2],a[3],a[4],a[5]);
        username=a[0];
        level=a[1];
        age=a[2];
        occupation=a[3];
        hobby=a[4];
        email=a[5];
    }
    virtual char* Save()
    {
        char *a=new char[CMAX];
        sprintf(a,"%d %s %s %s %s %s %s %s %s",ID,Name.c_str(),username.c_str(),level.c_str(),age.c_str(),occupation.c_str(),hobby.c_str(),email.c_str());
        return a;
    }
};
class film:public Base
{
public:
    string filmName;//影片名称
    string year;//上映年份
    string director;//导演
    string role;//主演
    string company;//出品公司
    string grade;//分级
    virtual void Print()
    {
        cout<<"ID:"<<ID<<" 影片名称:"<<filmName<<" 上映年份:"<<year<<" 导演:"<<director<<" 主演:"<<role<<"出品公司:"<<company<<"分级:"<<grade<<endl;
    }
    //返回类型名
    virtual void Input(){
        cout<<"输入影片名称:";
        cin>>filmName;
        cout<<"输入上映年份:";
        cin>>year;
        cout<<"输入导演:";
        cin>>director;
        cout<<"输入主演:";
        cin>>role;
        cout<<"输入出品公司:";
        cin>>company;
        cout<<"输入分级:";
        cin>>grade;
    }
    virtual void Reset(string name)
    {
        Name=name;
        cout<<"输入影片名称:";
        cin>>filmName;
        cout<<"输入上映年份:";
        cin>>year;
        cout<<"输入导演:";
        cin>>director;
        cout<<"输入主演:";
        cin>>role;
        cout<<"输入出品公司:";
        cin>>company;
        cout<<"输入分级:";
        cin>>grade;
    }
    virtual void Read(char *s){
        char a[5][CMAX];
        sscanf(s,"%d %s %s %s %s %s %s",&ID,a[0],a[1],a[2],a[3],a[4],a[5]);
        filmName=a[0];
        year=a[1];
        director=a[2];
        role=a[3];
        company=a[4];
        grade=a[5];
    }
    virtual char* Save()
    {
        char *a=new char[CMAX];
        sprintf(a,"%d %s %s %s %s %s %s %s",ID,Name.c_str(),filmName.c_str(),year.c_str(),director.c_str(),role.c_str(),company.c_str(),grade.c_str());
        return a;
    }
};
class comment:public Base
{
public:
    string username;//用户
    string moviename;//影片
    string score;//打分
    string connection;//影片链接
    string commentcount;//评价次数
    virtual void Print()
    {
        cout<<"ID:"<<ID<<" 用户:"<<username<<" 影片:"<<moviename<<" 打分:"<<score<<" 影片链接:"<<connection<<"评价次数:"<<commentcount<<endl;
    }
    //返回类型名
    virtual void Input(){
        cout<<"输入用户:";
        cin>>username;
        cout<<"输入影片:";
        cin>>moviename;
        cout<<"输入打分:";
        cin>>score;
        cout<<"输入影片链接:";
        cin>>connection;
        cout<<"输入评价次数:";
        cin>>commentcount;
    }
    virtual void Reset(string name)
    {
        Name=name;
        cout<<"输入用户:";
        cin>>username;
        cout<<"输入影片:";
        cin>>moviename;
        cout<<"输入打分:";
        cin>>score;
        cout<<"输入影片链接:";
        cin>>connection;
        cout<<"输入评价次数:";
        cin>>commentcount;
    }
    virtual void Read(char *s){
        char a[4][CMAX];
        sscanf(s,"%d %s %s %s %s %s %s",&ID,a[0],a[1],a[2],a[3],a[4]);
        username=a[0];
        moviename=a[1];
        score=a[2];
        connection=a[3];
        commentcount=a[4];
    }
    virtual char* Save()
    {
        char *a=new char[CMAX];
        sprintf(a,"%d %s %s %s %s %s %s %s",ID,Name.c_str(),username.c_str(),moviename.c_str(),score.c_str(),connection.c_str(),commentcount.c_str());
        return a;
    }
};
class List
{
public:
   
    Base *arr[MAX];
    int Length;
    int IDCount;//ID计数器
    List(){Length=0;IDCount=0;}
    bool AddNode(Base *node)
    {
        if(Length>MAX)
            return false;
        node->ID=IDCount++;
        arr[Length++]=node;
        return true;
    }
    bool Reset(int index,string name)
    {
        if(index<0||index>Length)
            return false;
        arr[index]->Reset(name);
        return true;
    }
    //按照序号删除
    bool DeleteNode(int index)
    {
        int i;
        if(index<0||index>Length)
            return false;
        free(arr[index]);
        for(i=index;i!=Length-1;++i)
            arr[i]=arr[i+1];
        --Length;
        return true;
    }
    //通过id查找,返回序号
    int Find(int id)
    {
        int i;
        for(i=0;i!=Length;++i)
            if(arr[i]->ID==id)
                return i;
        return -1;
    }
    //通过name查找,返回序号
    int Find(string name)
    {
        int i;
        for(i=0;i!=Length;++i)
            if(arr[i]->(name)==0)
                return i;
        return -1;
    }
    void ShowAll()
    {
        int i;
        for(i=0;i!=Length;++i)
            arr[i]->Print();
    }
    bool Read(int ii)
    {
        char FileName[3][CMAX]={"user.txt","film.txt","comment.txt"};
        char s[CMAX];
        FILE *f;
        f=fopen(FileName[ii],"r");
        if(f==NULL)
        {
            cout<<"打开失败"<<endl;
            return false;
        }
        fscanf(f,"%d %d\n",&Length,&IDCount);
        int i;
        for(i=0;i!=Length;++i)
        {
            fgets(s,CMAX,f);
            switch(ii)
            {
            case 0:arr[i]=new comment();break;
            case 1:arr[i]=new user();break;
            case 2:arr[i]=new film();break;
            }
            arr[i]->Read(s);
        }
        fclose(f);
        return true;
    }
    bool Save(int ii)
    {
        char FileName[3][CMAX]={"user.txt","film.txt","comment.txt"};
        FILE *f;
        f=fopen(FileName[ii],"w+");
        char *s;
        if(f==NULL)
        {
            cout<<"打开失败"<<endl;
            return false;
        }
        fprintf(f,"%d %d\n",Length,IDCount);
        int i;
        for(i=0;i!=Length;++i)
        {
            s=arr[i]->Save();
            fprintf(f,"%s\n",s);
        }
        fclose(f);
        return true;
    }
};
int inRange(int low,int up){
    int opt;
    cin>>opt;
    while(true){
        if(opt>=low&&opt<=up)
            break;
        cin.clear();//清空缓存
        cin.sync();
        cout<<"输入错误,请重新输入("<<low<<"-"<<up<<"):";
        cin>>opt;
    }
    return opt;
}
class System
{
private:
    List list[3];//
    void Init()
    {
        int i;
        for(i=0;i!=3;++i)
            list[i].Read(i);
    }
    void Add(int ii)
    {
        Base *k;
        switch(ii)
        {
        case 0:k=new comment();break;
        case 1:k=new user();break;
        case 2:k=new film();break;
        }
        k->Input();
        int index;
        index=list[ii].Find(k->Name);
        if(index!=-1)
        {
            cout<<"已经存在,添加失败"<<endl;
            return ;
        }
        if(!list[ii].AddNode(k))
            cout<<"添加失败"<<endl;
        else
            list[ii].Save(ii);
    }
    int Find(int ii)
    {
        cout<<"输入用户名";
        string name;
        cin>>name;
        int index;
        index=list[ii].Find(name);
        if(index==-1)
        {
            cout<<"未找到"<<endl;
            return -1;
        }
        list[ii].arr[index]->Print();
        return index;
    }
    void Reset(int ii)
    {
        int index,order;
        string name;
        index=Find(ii);
        if(index==-1)
            return ;
        cout<<"输入名字";
        cin>>name;
        order=list[ii].Find(name);
        if(order!=-1)
        {
            cout<<"改名字已经存在,修改失败"<<endl;
            return;
        }
        if(!list[ii].Reset(index,name))
        {
            cout<<"修改失败"<<endl;
            return ;
        }
        list[ii].Save(ii);
        cout<<"修改成功"<<endl;
    }
    void Delete(int ii)
    {
        int index;
        index=Find(ii);
        if(!list[ii].DeleteNode(index))
        {
            cout<<"删除失败"<<endl;
            return ;
        }
        cout<<"删除成功"<<endl;
        list[ii].Save(ii);
    }
    void Manage(int ii)
    {
        string kk[3]={"用户信息","影片信息","影评信息"};
        int order;
        while(true)
        {
            system("cls");
             cout<<" ---------------------------------"<<endl;
            cout<<"    "<<kk[ii]<<"影评信息系统管理"<<endl;
            cout<<"|----------------------------------|"<<endl;
            cout<<"|   请输入选项0-5                  |"<<endl;
            cout<<"|----------------------------------|"<<endl;
            cout<<"|    1.浏览                        |"<<endl;
            cout<<"|    2.增加                        |"<<endl;
            cout<<"|    3.查找                        |"<<endl;
            cout<<"|    4.修改                        |"<<endl;
            cout<<"|    5.删除                        |"<<endl;
            cout<<"|    0.返回                        |"<<endl;
            cout<<" ----------------------------------"<<endl;
            order=inRange(0,5);
            switch(order)
            {
            case 0:return;
            case 1:list[ii].ShowAll();break;
            case 2:Add(ii);break;
            case 3:Find(ii);break;
            case 4:Reset(ii);break;
            case 5:Delete(ii);break;
            }
            system("pause");
        }
    }
public:
    void mainrun()
    {
        Init();
        int order;
        while(true)
        {
            system("cls");
            cout<<" ----------------------- "<<endl;
            cout<<"|     请输入选项0-3     |"<<endl;
            cout<<"|-----------------------|"<<endl;
            cout<<"|    1.用户信息管理     |"<<endl;
            cout<<"|    2.影片信息管理     |"<<endl;
            cout<<"|    3.影评信息管理     |"<<endl;
            cout<<"|    0.退出系统         |"<<endl;
            cout<<" -----------------------"<<endl;
            order=inRange(0,4);
            switch(order)
            {
            case 0:return;
            case 1:Manage(1);break;
            case 2:Manage(2);break;
            case 3:Manage(0);break;
            }
            system("pause");
        }
    }
};

int main()
{
    System sys;
    sys.mainrun();
    system("pause");
    return 0;
}
[附[local]2[/local][local]3[/local][local]4[/local]件]1[/附件]
图片附件: 游客没有浏览图片的权限,请 登录注册
图片附件: 游客没有浏览图片的权限,请 登录注册
图片附件: 游客没有浏览图片的权限,请 登录注册


[此贴子已经被作者于2019-6-13 14:13编辑过]

搜索更多相关主题的帖子: Name int cout 输入 cin 
2019-06-13 14:07
我挺好
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2019-7-28
收藏
得分:0 
为啥只能存一个  而且搜不了
2019-07-28 17:24
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9029
专家分:54050
注 册:2011-1-18
收藏
得分:0 
因为你的 film::Input 根本没修改 Base::Name,自然找不到 Base::Name=="1" 的节点。
2019-07-29 16:39
快速回复:《观影网站影评信息管理系统》课设作业(编译运行都可以,就是结果不对 ...
数据加载中...
 
   



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

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