VS为什么代码存储时出现了,无法读取内存的情况,求大神解救

abcddddaad 2016-12-18 10:44:19
#include <iostream>
#include <string>
using namespace std;
struct Dancer
{
int num; //舞者号
string name; //姓名
int age; //年龄
string sex; //性别
int height; //身高
int weight; //体重
string type; //舞蹈种类
};
struct Node
{
Dancer data;
struct Node *next;
};
class DancerList
{
public:
DancerList()
{
Node *first = new Node;
first->next = NULL;
}
~DancerList()
{
Node *p, *q;
p = first;
while (p)
{
q = p;
p = p->next;
delete q;
}
}
void Insert() //增加
{
Node *z;
z = new Node;
cout << "num:";
cin >> z->data.num;
cout << "name:";
cin >> z->data.name;
cout << "sex:";
cin >> z->data.sex;
cout << "age:";
cin >> z->data.age;
cout << "height:";
cin >> z->data.height;
cout << "weight:";
cin >> z->data.weight;
cout << "type:";
cin >> z->data.type;
z->next = first->next;
first->next = z;
}
void Delete(int num)
{
Node *p , *q;
q = first;
p = q->next;
while (p)
{
if (p->data.num == num)
break;
q = p;
p = p->next;
}
if (p == NULL)
cout << "error num" << endl;
else
{
q->next = p->next;
delete p;
}
}

void Modify(int num)
{
Node *p, *q;
q = first;
p = q->next;
while (p)
{
if (p->data.num == num)
break;
q = p;
p = p->next;
}
if (p == NULL)
cout << "error num" << endl;
else
{
cout << "修改:";
cout << "num:";
cin >> p->data.num;
cout << "name:";
cin >> p->data.name;
cout << "sex:";
cin >> p->data.sex;
cout << "age:";
cin >> p->data.age;
cout << "height:";
cin >> p->data.height;
cout << "weight:";
cin >> p->data.weight;
cout << "type:";
cin >> p->data.type;
cout << "修改成功" << endl;
}
}
Node *Search(int num)
{
Node *p;
p = first->next;
while (p)
{
if (p->data.num == num)
break;
p = p->next;
}
return p;
}

int Count()
{
int count = 0;
Node *p;
p = first->next;
while (p)
{
count++;
p = p->next;
}
cout << "已录入舞者个数::" << count << endl;
return count;
}
void output()
{
cout << "编号" << '\t' << "姓名" << '\t' << "性别" << '\t' << "年龄" << '\t' << "身高" << '\t' << "体重" << '\t' << "舞种" << endl;
struct Node *p;
p = first->next;
while (p)
{
cout << p->data.num << '\t' << p->data.name << '\t' << p->data.sex << '\t' << p->data.age << '\t';
cout << p->data.height << '\t' << p->data.weight << '\t' << p->data.type << endl;
p = p->next;
}
}

private:
Node *first;
};
#include "dancer1.h"
#include <iostream>
#include <string>
using namespace std;

int main()
{
DancerList d;
int choice=1;
int n=0;
int k=0;
int t=0;
Node *p;
while(choice!=8)
{
cout<<" ************************************** "<<endl;
cout<<" * * "<<endl;
cout<<" * 1.Insert * "<<endl;
cout<<" * 2.Delete * "<<endl;
cout<<" * 3.Modify * "<<endl;
cout<<" * 4.Search * "<<endl;
cout<<" * 5.Count * "<<endl;
cout<<" * 6.Output * "<<endl;
cout<<" * 7.Sort * "<<endl;
cout<<" * 8.Exit * "<<endl;
cout<<" * * "<<endl;
cout<<" ************************************** "<<endl;
cout<<endl;
cout<<"please input choice:";
cin>>choice;
switch(choice)
{
case 1:
d.Insert();
break;
case 2:
cout<<"请输入要删除的舞者信息编号:"<<endl;
cin>>n;
d.Delete(n);
break;
case 3:
cout<<"请输入要修改的舞者信息编号:"<<endl;
cin>>k;
d.Modify(k);
break;
case 4:
cout<<"请输入要查询的编号:"<<endl;
cin>>t;
p=d.Search(t);
break;
case 5:
d.Count();
break;
case 6:
d.output();
break;

}
}
return 0;
}
...全文
471 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧