手机短信的程序改改

Jason.lai 2008-12-22 12:58:45
//信息中的发信息、收信息、已发信息和发信箱储存信息的内容和电话号码。
//一条信息的最大容量为70个字节。容量状态则表示手机储存的短信的条数。
//手机的最大储存量为200条。当超过这数时,显示储存信息已满,请及时删除无用信息。
#include<iostream.h>
#include<string.h>
#include<stdlib.h>
#include<fstream.h>
#define Max 200
#define Mao 70
//using namespace std;
class News
{
public:
News(){}
void setnews();//写信信
void sentnews();//发信息
void recivenews();//收信息
void asentnews();//已发信息
void sentnewsbox();//发信箱
void savenews();//保存信息
void deletenews();//删除信息
void quit();//退出
private:
string news;//信息
string telenumber;//电话号码
static int number;//计数信息的数量
};
int News::number=0;
void News::setnews()//写信息
{
system("cls");
cout<<"新建信息(以#结束):";
cin>>news;
cout<<"你已建立信息!!!"<<endl;
char choice;
cout<<"保存与否(Y/N):";
cin>>choice;
if(choice=='Y'||choice=='y')
{
savenews();
number++;
}
else
cout<<"你没有保存信息,退出!!!"<<endl;
}
void News::sentnews()//发信息
{
system("cls");
cout<<"新建信息:";
setnews();
cout<<"请输入电话号码(数字):";
cin>>telenumber;
cout<<"\t确定(Y)\t取消(N)"<<endl;
char choice;
cin>>choice;
if(choice=='Y'||choice=='y')
{
system("pause");
cout<<"已发送信息!!!"<<endl;
asentnews();
}
else
cout<<"你已取消发送信息!!!"<<endl;
}
void News::sentnewsbox()//发信箱
{
cout<<"\t你的发信箱的已用空间:"<<number<<endl;
if(number>=195)
{
cout<<"\t你的发信箱的空间即将使用完!!!"<<endl;
cout<<"\t请及时删除无用信息!!!"<<endl;
}
}
void News::asentnews()//已发信息
{
ifstream infile;
infile.open("D://News.txt",ios::out|ios::in|ios::app);
if(!infile)
{
cerr<<"无法打开此文件!!!"<<endl;
exit(0);
}
else
{
while(!infile.eof())
{
int n=1;
cout<<"第"<<n<<"条信息:"<<endl;
cout<<"电话号码(11位):";
infile>>telenumber;
cout<<"信息内容如下:"<<endl;
infile>>news;
cout<<news;
cout<<endl;
}
cout<<"\t\t删除信息与否(Y/N)";
char choice;
cin>>choice;
if(choice=='Y'||choice=='y')
{
//删除信息文件内存中删除
deletenews();
}
else
{
cout<<"你已取消删除信息!退出!!"<<endl;
infile.close();
}
}
}
void News::recivenews()//收信息
{
cout<<"输入你要接受信息的号码:";
string telephone;
cin>>telephone;
cout<<"\t\t已接受信息"<<endl;
savenews();//保存接受的信息
ofstream outfile;
outfile.open("D://News.txt",ios::out);
if(!outfile)
{
cerr<<"无法打开此文件!!!"<<endl;
exit(1);
}
else
{
while(!outfile.eof())
{
int n=1;
cout<<"第"<<n<<"条信息:"<<endl;
cout<<"电话号码:";
outfile<<telenumber;
cout<<"信息内容如下:"<<endl;
outfile<<news;
cout<<news;
cout<<endl;
}
cout<<"\t\t删除信息与否(Y/N)";
char choice;
cin>>choice;
if(choice=='Y'||choice=='y')
{
//删除信息文件内存中删除
deletenews();
}
else
{
cout<<"你已取消删除信息!退出!!"<<endl;
outfile.close();
}
}
}
void News::savenews()//保存信息
{
ifstream infile;
infile.open("D://News.txt",ios::in|ios::app|ios::out);
if(!infile)
{
cerr<<"无法打开此文件!!!"<<endl;
exit(1);
}
else
{
while(infile.eof())
{
//写入文件,保存信息
infile>>news;
infile>>telenumber;
}
infile.close();
}
}
void News::deletenews()//删除信息
{
ofstream outfile;
outfile.open("D://News.txt",ios::out);
if(!outfile)
{
cerr<<"无法打开此文件!!!"<<endl;
exit(1);
}
else
{
int n=1;
while(outfile.eof())
{
outfile<<news;
outfile<<telenumber;
n++;
}
//这里不会匹配删除的信息
number--;
outfile.close();
}
}
void News::quit()
{
for(int i=0;i<40;i++)
cout<<"* ";
cout<<"\t\t\t谢谢使用信息系统"<<endl;
for(i=0;i<40;i++)
cout<<"* ";
cout<<endl;
}
int main()
{
News NEWS;
for(int i=0;i<40;i++)
cout<<"* ";
cout<<"\t\t\t欢迎进入信息系统"<<endl;
for(i=0;i<40;i++)
cout<<"* ";
for(;;)
{
cout<<"\t\t新建信息----------------------(1)"<<endl;
cout<<"\t\t发信息------------------------(2)"<<endl;
cout<<"\t\t收信息------------------------(3)"<<endl;
cout<<"\t\t已发信息----------------------(4)"<<endl;
cout<<"\t\t发信箱------------------------(5)"<<endl;
cout<<"\t\t退出--------------------------(0)"<<endl;
cout<<"\t选择操作项目:";
int choice;
cin>>choice;
switch(choice)
{
case 1:NEWS.setnews();break;
case 2:NEWS.sentnews();break;
case 3:NEWS.recivenews();break;
case 4:NEWS.asentnews();break;
case 5:NEWS.sentnewsbox();break;
case 0:
default:
NEWS.quit();return 0;break;
}
}
}
...全文
141 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Jason.lai 2008-12-24
  • 打赏
  • 举报
回复
谢了!!!
shexinwei 2008-12-23
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 laibinghua 的回复:]
虽然已经通过了,但是还有部分的代码有问题。像发信息、收信息、已发信息。这个程序代码是模拟现实的手机的短信接收的。你能不能帮忙改改。谢了!!
[/Quote]
好,我有时间帮你改,先看一看你的程序!!
Jason.lai 2008-12-23
  • 打赏
  • 举报
回复
虽然已经通过了,但是还有部分的代码有问题。像发信息、收信息、已发信息。这个程序代码是模拟现实的手机的短信接收的。你能不能帮忙改改。谢了!!
shexinwei 2008-12-23
  • 打赏
  • 举报
回复
楼主:首先本人觉得你的草稿箱,和你的发件箱为两个文件,所以我建了一个新建信息.txt作为草稿箱,建了一个发件箱.txt作为你的已发信息!由于收信息信息
没想到更好的模拟方法,收信息功能是从你的草稿箱里面收取信息。删除信息的功能暂时还不能帮你实现!!呵呵,我继续做!
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
//#include <stdlib.h>
#define Max 200
#define Mao 70
//using namespace std;
class News
{
public:
News(){}
void setnews();//写信息
void sentnews();//发信息
void recivenews();//收信息
void asentnews();//已发信息
void sentnewsbox();//发信箱
void savenews();//保存信息
void deletenews();//删除信息
void quit();//退出
private:
string news;//信息
string telenumber;//电话号码
};
int number=0; //统计发件箱信息
void News::setnews()//写信息
{
system("cls");
cout <<"新建信息(以#结束):";
cin>>news;
cout <<"你已建立信息!!!" <<endl;
char choice;
cout <<"保存与否(Y/N):";
cin>>choice;
if(choice=='Y'||choice=='y')
{
savenews();
number++;
}
else
cout <<"你没有保存信息,退出!!!" <<endl;
}
void News::sentnews() //发信息
{
system("cls");
cout <<"新建信息:";
setnews();
cout <<"请输入电话号码(数字):";
cin>>telenumber;
cout <<"\t确定(Y)\t取消(N)" <<endl;
char choice;
cin>>choice;
if(choice=='Y'||choice=='y')
{ number++;
system("pause");
cout <<"已发送信息!!!" <<endl;
ofstream outfile;
outfile.open("发件箱.txt",ios::out|ios::app); //将信息存入发件箱
if(!outfile)
{
cerr <<"无法打开此文件!!!" <<endl;
exit(1);
}
else
{
outfile<<news<<endl;
outfile<<telenumber<<endl;
outfile.close();
}
}
else
cout <<"你已取消发送信息!!!" <<endl;
}
void News::sentnewsbox() //发信箱
{
cout <<"\t你的发信箱的已用空间:" <<number <<endl;
if(number>=195)
{
cout <<"\t你的发信箱的空间即将使用完!!!" <<endl;
cout <<"\t请及时删除无用信息!!!" <<endl;
}
system("pause");
}
void News::asentnews() //已发信息
{
ifstream infile;
infile.open("发件箱.txt");
if(!infile)
{
cerr <<"无法打开此文件!!!" <<endl;
exit(0);
}
else
{ int n=1;
while(1)
{
cout <<"第" <<n <<"条信息:" <<endl;
cout <<"信息内容如下: ";
infile>>news;
cout <<news<<endl;
cout <<"电话号码(11位): ";
infile>>telenumber;
cout<<telenumber<<endl;
cout <<endl;
if (!infile.eof())
break;
n++;
}
cout <<"\t\t删除信息与否(Y/N)";
char choice;
cin>>choice;
if(choice=='Y'||choice=='y')
{
//删除信息文件内存中删除
deletenews();
}
else
{
cout <<"你已取消删除信息!退出!!" <<endl;
infile.close();
}
}
}
void News::recivenews() //收信息
{
cout <<"输入你要接受信息的号码:";
string telephone;
cin>>telephone;
cout <<"\t\t已接受信息" <<endl;
savenews(); //保存接受的信息
ifstream infile;
infile.open("新建信息.txt",ios::in);
if(!infile)
{
cerr <<"无法打开此文件!!!" <<endl;
exit(1);
}
else
{ int n=1;
while(1)
{cout <<"第" <<n <<"条信息:" <<endl;
cout <<"信息内容如下:" <<endl;
infile>>news;
cout<<news<<endl;
n++;
if (!infile.eof())
break;
}
cout <<"\t\t删除信息与否(Y/N)";
char choice;
cin>>choice;
if(choice=='Y'||choice=='y')
{
deletenews(); //删除信息文件内存中删除
}
else
{
cout <<"你已取消删除信息!退出!!" <<endl;
infile.close();
}
}
}
void News::savenews() //保存信息
{
ofstream outfile;
outfile.open("新建信息.txt",ios::out|ios::app);
if(!outfile)
{
cerr <<"无法打开此文件!!!" <<endl;
exit(1);
}
else //while(outfile.eof())
{
//写入文件,保存信息
outfile<<news<<endl;
//outfile<<telenumber;
//}
outfile.close();
}
}
void News::deletenews()//删除信息
{
ofstream outfile;
outfile.open("D://News.txt",ios::out);
if(!outfile)
{
cerr <<"无法打开此文件!!!" <<endl;
exit(1);
}
else
{
int n=1;
while(outfile.eof())
{
outfile <<news;
outfile <<telenumber;
n++;
}
//这里不会匹配删除的信息
number--;
outfile.close();
}
}
void News::quit()
{
for(int i=0;i <40;i++)
cout <<"* ";
cout <<"\t\t\t谢谢使用信息系统" <<endl;
for(i=0;i <40;i++)
cout <<"* ";
cout <<endl;
}
int main()
{
News NEWS;
for(;;)
{ system("cls");
for(int i=0;i <40;i++)
cout <<"* ";
cout <<"\t\t\t欢迎进入信息系统" <<endl;
for(i=0;i<40;i++)
cout <<"* ";
cout <<"\t\t新建信息----------------------(1)" <<endl;
cout <<"\t\t发信息------------------------(2)" <<endl;
cout <<"\t\t收信息------------------------(3)" <<endl;
cout <<"\t\t已发信息----------------------(4)" <<endl;
cout <<"\t\t发信箱------------------------(5)" <<endl;
cout <<"\t\t退出--------------------------(0)" <<endl;
cout <<"\t选择操作项目:";
int choice;
cin>>choice;
switch(choice)
{
case 1:NEWS.setnews();break;
case 2:NEWS.sentnews();break;
case 3:NEWS.recivenews();break;
case 4:NEWS.asentnews();break;
case 5:NEWS.sentnewsbox();break;
case 0:
default:
NEWS.quit();return 0;break;
}
}
}
Jason.lai 2008-12-23
  • 打赏
  • 举报
回复
谢了,最好快点,这星期要上交的,先谢了!!!!!!!!!!!!!!!!!!!!
liuyuanyang 2008-12-22
  • 打赏
  • 举报
回复
这个不可能在手机上跑的!
模拟??
发短信 ?…… symbian 有,不用写了
MyCppPython2008 2008-12-22
  • 打赏
  • 举报
回复
这个不可以在手机平台上跑吧,是模拟逻辑吧。
shexinwei 2008-12-22
  • 打赏
  • 举报
回复
不知楼主想问什么问题,测试通过了;
#include <iostream>
#include <string>
#include <fstream>

using namespace std;
//#include <stdlib.h>

#define Max 200
#define Mao 70
//using namespace std;
class News
{
public:
News(){}
void setnews();//写信信
void sentnews();//发信息
void recivenews();//收信息
void asentnews();//已发信息
void sentnewsbox();//发信箱
void savenews();//保存信息
void deletenews();//删除信息
void quit();//退出
private:
string news;//信息
string telenumber;//电话号码
static int number;//计数信息的数量
};
int News::number=0;
void News::setnews()//写信息
{
system("cls");
cout <<"新建信息(以#结束):";
cin>>news;
cout <<"你已建立信息!!!" <<endl;
char choice;
cout <<"保存与否(Y/N):";
cin>>choice;
if(choice=='Y'||choice=='y')
{
savenews();
number++;
}
else
cout <<"你没有保存信息,退出!!!" <<endl;
}
void News::sentnews()//发信息
{
system("cls");
cout <<"新建信息:";
setnews();
cout <<"请输入电话号码(数字):";
cin>>telenumber;
cout <<"\t确定(Y)\t取消(N)" <<endl;
char choice;
cin>>choice;
if(choice=='Y'||choice=='y')
{
system("pause");
cout <<"已发送信息!!!" <<endl;
asentnews();
}
else
cout <<"你已取消发送信息!!!" <<endl;
}
void News::sentnewsbox()//发信箱
{
cout <<"\t你的发信箱的已用空间:" <<number <<endl;
if(number>=195)
{
cout <<"\t你的发信箱的空间即将使用完!!!" <<endl;
cout <<"\t请及时删除无用信息!!!" <<endl;
}
}
void News::asentnews()//已发信息
{
ifstream infile;
infile.open("D://News.txt",ios::out|ios::in|ios::app);
if(!infile)
{
cerr <<"无法打开此文件!!!" <<endl;
exit(0);
}
else
{
while(!infile.eof())
{
int n=1;
cout <<"第" <<n <<"条信息:" <<endl;
cout <<"电话号码(11位):";
infile>>telenumber;
cout <<"信息内容如下:" <<endl;
infile>>news;
cout <<news;
cout <<endl;
}
cout <<"\t\t删除信息与否(Y/N)";
char choice;
cin>>choice;
if(choice=='Y'||choice=='y')
{
//删除信息文件内存中删除
deletenews();
}
else
{
cout <<"你已取消删除信息!退出!!" <<endl;
infile.close();
}
}
}
void News::recivenews()//收信息
{
cout <<"输入你要接受信息的号码:";
string telephone;
cin>>telephone;
cout <<"\t\t已接受信息" <<endl;
savenews();//保存接受的信息
ofstream outfile;
outfile.open("D://News.txt",ios::out);
if(!outfile)
{
cerr <<"无法打开此文件!!!" <<endl;
exit(1);
}
else
{
while(!outfile.eof())
{
int n=1;
cout <<"第" <<n <<"条信息:" <<endl;
cout <<"电话号码:";
outfile <<telenumber;
cout <<"信息内容如下:" <<endl;
outfile <<news;
cout <<news;
cout <<endl;
}
cout <<"\t\t删除信息与否(Y/N)";
char choice;
cin>>choice;
if(choice=='Y'||choice=='y')
{
//删除信息文件内存中删除
deletenews();
}
else
{
cout <<"你已取消删除信息!退出!!" <<endl;
outfile.close();
}
}
}
void News::savenews()//保存信息
{
ifstream infile;
infile.open("D://News.txt",ios::in|ios::app|ios::out);
if(!infile)
{
cerr <<"无法打开此文件!!!" <<endl;
exit(1);
}
else
{
while(infile.eof())
{
//写入文件,保存信息
infile>>news;
infile>>telenumber;
}
infile.close();
}
}
void News::deletenews()//删除信息
{
ofstream outfile;
outfile.open("D://News.txt",ios::out);
if(!outfile)
{
cerr <<"无法打开此文件!!!" <<endl;
exit(1);
}
else
{
int n=1;
while(outfile.eof())
{
outfile <<news;
outfile <<telenumber;
n++;
}
//这里不会匹配删除的信息
number--;
outfile.close();
}
}
void News::quit()
{
for(int i=0;i <40;i++)
cout <<"* ";
cout <<"\t\t\t谢谢使用信息系统" <<endl;
for(i=0;i <40;i++)
cout <<"* ";
cout <<endl;
}
int main()
{
News NEWS;
for(int i=0;i <40;i++)
cout <<"* ";
cout <<"\t\t\t欢迎进入信息系统" <<endl;
for(i=0;i<40;i++)
cout <<"* ";
for(;;)
{
cout <<"\t\t新建信息----------------------(1)" <<endl;
cout <<"\t\t发信息------------------------(2)" <<endl;
cout <<"\t\t收信息------------------------(3)" <<endl;
cout <<"\t\t已发信息----------------------(4)" <<endl;
cout <<"\t\t发信箱------------------------(5)" <<endl;
cout <<"\t\t退出--------------------------(0)" <<endl;
cout <<"\t选择操作项目:";
int choice;
cin>>choice;
switch(choice)
{
case 1:NEWS.setnews();break;
case 2:NEWS.sentnews();break;
case 3:NEWS.recivenews();break;
case 4:NEWS.asentnews();break;
case 5:NEWS.sentnewsbox();break;
case 0:
default:
NEWS.quit();return 0;break;
}
}
}
楼主看着给分吧!!呵呵!!

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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