首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

求更改下小弟我写的程序与一些有关问题

2012-03-17 
求更改下我写的程序与一些问题#include iostream#include string#include fstream#include iomanip

求更改下我写的程序与一些问题
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
#include <string.h>
#include <conio.h>
#include<stdio.h>
fstream iofile;
struct Node
{
string Name; //姓名
double BasicWage;//基本工资
double Reward; //奖金
double Forfeit; //罚款
Node *next;
};
class A
{
private:
Node *head;
public:
A(Node *h)
{
head=h;
}
~A()
{
}
Node * Create();
void Release();
Node *Insert();
void seek();
Node * Change();
void menu();
void count();
void File(fstream & ofile);
};
Node * A::Create() 

head=(Node *)new Node; 
if(!head) 

cout<<"分配内存失败!"<<endl; 
return NULL; 

head->Name=" "; 
head->BasicWage=0; 
head->Reward=0; 
head->Forfeit=0;  
head->next=NULL; 
return head; 
}
//释放链表
void A::Release() 

Node * ptr; //声明一个操作用的指针。 
while(head!=NULL) 

ptr=head; 
head=head->next; 
delete ptr; //释放节点资源。 


void print(Node * ptr)
{
cout<<"姓名:"<<ptr->Name<<endl;
cout<<"基本工资:"<<ptr->BasicWage<<endl;
cout<<"奖金:"<<ptr->Reward<<endl;
cout<<"罚款:"<<ptr->Forfeit<<endl;
cout<<"总和:"<<ptr->BasicWage+ptr->Reward-ptr->Forfeit<<endl;
}
Node * A::Insert() 
{
Node *pNew; //声明一个新节点 
char again; 
string Cname;
double CbasicWage,Creward,Cforfeit;
do 

pNew=(Node *)new Node;
cout<<"请输入姓名:"; 
cin>>Cname; 
cout<<endl<<"请输入基本工资:"; 
cin>>CbasicWage; 
cout<<endl<<"请输入奖金:"; 
cin>>Creward;
cout<<endl<<"请输入罚款数:"; 
cin>>Cforfeit;  
cout<<endl; 
pNew->Name=Cname; 
pNew->BasicWage=CbasicWage; 
pNew->Reward=Creward; 
pNew->Forfeit=Cforfeit;  
pNew->next=head->next; 
head->next=pNew; 
cout<<"数据添加成功!是否继续添加?(Y/N)"<<endl; 
cin>>again; 
}while(again=='Y'||again=='y'); 
return head; 

void A::File(fstream & ofile) 

Node * pNode; 
pNode=head->next; 
ofile.clear(); //清除文件结束状态。 
while(pNode) 

ofile<<setw(10)<<left<<"姓名"<<setw(10)<<left<<"基本工资"<<setw(10)<<left<<"奖金"<<setw(10)<<left<<"罚单"<<setw(10)<<left<<"应付工资"<<endl;
ofile<<setw(10)<<left<<pNode->Name 
<<setw(10)<<left<<pNode->BasicWage
<<setw(10)<<left<<pNode->Reward
<<setw(10)<<left<<pNode->Forfeit
<<setw(10)<<left<<pNode->BasicWage+pNode->Reward-pNode->Forfeit
<<endl; 
pNode=pNode->next; 

cout<<"数据文件保存成功!"<<endl;

void main()
{
Node *head=0;
A a(head);
head=a.Create();
iofile.open("E:工资.xls",ios_base::in|ios_base::out|ios_base::app);
if(!iofile) 



cout<<"打开文件失败!"<<endl; 

a.Insert();
a.File(iofile);
}
以上是我做的一个工资结算的程序,但是现在需要姓名是本来就有的,已经保存了的,输入数据只需要输入基本工资,奖金,罚单。程序界面出现的是请输入张三的基本工资,请输入张三的奖金。。。。而不是请输入姓名,请输入基本工资。。。然后就是我用文件保存的方法保存为XLS格式,但是打开EXCEL发现输入的数据全部在一个单元格里面,如何让数据分开,各占一个单元格?

[解决办法]
保存CSV会简单一点,excel也支持的
[解决办法]

C/C++ code
void A::File(fstream & ofile)  {  Node * pNode;  pNode=head->next;  ofile.clear(); //清除文件结束状态。  while(pNode)  {  ofile<<setw(10)<<left<<"姓名\t"<<left<<"基本工资\t"<<left<<"奖金\t"<<left<<"罚单\t"<<left<<"应付工资"<<endl;ofile<<left<<pNode->Name<<"\t"  <<left<<pNode->BasicWage<<"\t" <<left<<pNode->Reward<<"\t" <<left<<pNode->Forfeit<<"\t" <<left<<pNode->BasicWage+pNode->Reward-pNode->Forfeit<<endl;  pNode=pNode->next;  }  cout<<"数据文件保存成功!"<<endl; } 

热点排行