
请问各路高手几个关于几个C语言的问题。感激不尽!!!
2、设计一个程序,要求能打开一个指定的24为彩色BMP图像文件,将该图像数据部分每个像素BGR3个分量的值进行简单的运行后形成一个新B'G'R',最后生成一个新图像文件(黑白)。也要运行结果截图 展开
#include <iostream>
#include <string>
using namespace std;
class LuckyNumber //幸运者类
{
public:
LuckyNumber();
int Total();//构造函数
void Display();//打印
bool Insert(const int& value, const string& name);//添加
bool Delete(const int& number);//根据幸运者数字删除
bool Modification(const string& name, const int& number);//修改
string Inquires(const int& number);//根据幸运者数字查询姓名
int Inquires(const string& name);//根据幸运者姓名查询号码
private:
string name;//幸运者姓名
int number;//幸运者号码
LuckyNumber* next;//连接下一个节点
};
LuckyNumber::LuckyNumber()
{
this ->next = NULL;
this ->name = "头节点";
this ->number = 0;
}
int LuckyNumber::Total()
{
int count = 0;
LuckyNumber* current = this ->next;
while(current != NULL)
{
count++;
current = current ->next;
}
cout<<"幸运者总数:"<<count<<endl;
return count;
}
void LuckyNumber::Display()
{
if (0 == Total())
{
cout<<"无幸运者!"<<endl;
return ;
}
LuckyNumber* current = this ->next;
while(current != NULL)
{
cout<<"幸运者姓名:"<<current->name<<",幸运数字:"<<current->number<<endl;
current = current ->next;
}
return ;
}
bool LuckyNumber::Insert(const int& value, const string& name)//为方便起见,将新增幸运者加入到头结点后面
{
LuckyNumber* temp = new LuckyNumber;
temp ->name = name;
temp ->number = value;
temp ->next = this ->next;
this ->next = temp;
cout<<"幸运者 "<<name<<" 被成功添加!"<<endl;
return true;
}
bool LuckyNumber::Delete(const int& number)
{
if (0 == Total())
{
cout<<"已无幸运者!"<<endl;
return false;
}
LuckyNumber* current = this ->next;
LuckyNumber* temp = this;
while(current != NULL)
{
if(current ->number == number)
{
temp ->next = current ->next;
delete current;
cout<<"幸运数字为 "<<number<<" 的幸运者被成功删除!"<<endl;
return true;
}
else
{
current = current ->next;
temp = temp ->next;
}
}
cout<<"无此幸运数字!"<<endl;
return false;
}
bool LuckyNumber::Modification(const string& name, const int& number)
{
LuckyNumber* current = this ->next;
while(current != NULL)
{
if (current ->name == name)
{
current ->number = number;
cout<<"幸运者 "<<name<<" 的幸运数字已成功更改!"<<endl;
return true;
}
else
current = current ->next;
}
cout<<"查无此人!"<<endl;
return false;
}
int LuckyNumber::Inquires(const string& name)
{
if (Total() == 0)
{
cout<<"无幸运者!"<<endl;
return false;
}
LuckyNumber* current = this ->next;
while(current != NULL)
{
if (current ->name == name)
return current ->number;
else
current = current ->next;
}
cout<<"查无此人"<<endl;
return -1;
}
string LuckyNumber::Inquires(const int& number)
{
if (Total() == 0)
return "无幸运者";
LuckyNumber* current = this ->next;
while(current != NULL)
{
if (current ->number == number)
return current ->name;
else
current = current ->next;
}
return "查无此号!";
}
int main()
{
LuckyNumber person;
person.Insert(10001, "张三");
person.Insert(10002, "李四");
person.Insert(10003, "王五");
person.Display();
person.Delete(10001);
person.Display();
/*
……
里面可以自己写代码测试,我就不写了哈!写代码好辛苦啊,楼主追加点分吧,第二个题还在做,先把第一个发上来再说哦
……
……
*/
return 0;
}
2010-12-30