用C语言程序编一个个人所得税的源程序,求高手解答
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用C语言程序编一个个人所得税的源程序,求高手解答相关的知识,希望对你有一定的参考价值。
就是一个能计算个人所得税的源程序
参考技术A /*算法设计参考: http://baike.baidu.com/view/118.htm
算法:(总工资)-(三险一金)-(免征额)X税率-速扣数=个人所得税
全月应纳税所得额 税率 速算扣除数(元)
全月应纳税额不超过1500元 3% 0
全月应纳税额超过1500元至4500元 10% 105
全月应纳税额超过4500元至9000元 20% 555
全月应纳税额超过9000元至35000元 25% 1005
全月应纳税额超过35000元至55000元 30% 2755
全月应纳税额超过55000元至80000元 35% 5505
全月应纳税额超过80000元 45% 13505
*/#include <stdio.h>int main()
float money;//总金额
float submoney;//不应缴税金额
float result;//税收
float realmoney;//应缴税金额
scanf("%f",&money);//输入金额
scanf("%f",&submoney);//输入不应缴税金额
realmoney = money - submoney - 0;
if(realmoney <= 0)
result = 0;
else if(realmoney <= 1500 )//全月应纳税额不超过1500元
result = realmoney*0.03;
else if(realmoney <= 4500 )//全月应纳税额不超过4500元
result = realmoney*0.1-105;
else if(realmoney <= 9000 )//全月应纳税额不超过9000元
result = realmoney*0.2-555;
else if(realmoney <= 35000 )//全月应纳税额不超过35000元
result = realmoney*0.25-1005;
else if(realmoney <= 55000 )//全月应纳税额不超过55000元
result = realmoney*0.3-2755;
else if(realmoney <= 80000 )//全月应纳税额不超过80000元
result = realmoney*0.35-5505;
else//全月应纳税额超过80000元
result = realmoney*0.4-13505;
printf("个人所得税为:%.2f\n",result);
return 0;
参考技术B 你是说现在的交税率?
我们数据结构实验课让用C++做一个二叉树的遍历的程序,老师也没讲过具体怎么弄,求高手解答!
请从用什么软件讲起……我们学过C++,但是数据结构课用的是清华大学的教材,老师说上面用的语言是类C,然后也没讲过用什么语句什么的突然就叫我们写程序,都不会啊……
我们用的软件是Microsoft Visual C++ 6.0
求高手!求讲解!
自己写的,运行通过,MFC的有点难弄,将就着用吧。
queue.h//链式队列用于层序遍历树
// queue.h: interface for the queue class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_QUEUE_H__6515EF6D_27AA_4799_95F8_6FE216E99F0F__INCLUDED_)
#define AFX_QUEUE_H__6515EF6D_27AA_4799_95F8_6FE216E99F0F__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <iostream.h>
#include <assert.h>
template<class T>
struct LinkNode
T data;
LinkNode<T> *link;
LinkNode(LinkNode<T> *ptr = NULL)link = ptr;//仅初始化指针成员的初始函数.
LinkNode(const T& item,LinkNode<T> *ptr = NULL)
data = item;link = ptr; //初始化数据与指针成员的构造函数.
;
template <class T>
class queue
private:
LinkNode<T> *front,*rear;//
public:
queue():rear(NULL),front(NULL);//
~queue()makeempty();;//
bool EnQueue(T &x);//
bool DeQueue(T &x);//
bool getFront(T &x);//
void makeempty();//
bool Isempty()constreturn front==NULL;//
int getSize()const;//
friend ostream &operator<<(ostream &os,queue<T> &q);//
;
template<class T>
void queue<T>::makeempty()
LinkNode<T> *p;
while(front!=NULL)
p=front;
front=front->link;
delete p;
template <class T>
bool queue<T>::EnQueue(T &x)
if(front==NULL)
front=rear=new LinkNode<T>(x);
if(front==NULL)
return false;
else
rear->link=new LinkNode<T>(x);
if(rear==NULL)
return false;
rear=rear->link;
return true;
template <class T>
bool queue<T>::DeQueue(T &x)
if(Isempty())return false;
LinkNode<T> *p=front;
x=front->data;
front=front->link;
delete p;
return true;
template<class T>
bool queue<T>::getFront(T &x)
if(Isempty())return false;
x=front->data;
return true;
template <class T>
int queue<T>::getSize() const
LinkNode<T> *p=front;
int k=0;
while(p)
k++;
p=p->link;
return k;
#endif // !defined(AFX_QUEUE_H__6515EF6D_27AA_4799_95F8_6FE216E99F0F__INCLUDED_)
BinaryTree.h
// BinaryTree.h: interface for the BinaryTree class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_BINARYTREE_H__61FEB349_65EE_40FB_82DF_25FFBCBDFC6E__INCLUDED_)
#define AFX_BINARYTREE_H__61FEB349_65EE_40FB_82DF_25FFBCBDFC6E__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <iostream.h>
typedef int T;
struct BinTreeNode
T data;
BinTreeNode *leftChild,*rightChild;
BinTreeNode():leftChild(NULL),rightChild(NULL)
BinTreeNode(T x,BinTreeNode *l=NULL,BinTreeNode *r=NULL):data(x),leftChild(l),rightChild(r)
;
class BinaryTree
public:
BinaryTree():root(NULL) //
BinaryTree(T value):RefValue(value) ,root(NULL) //
~BinaryTree()destroy(root);/////////
void CreateBinTree()CreateBinTree(root);
bool IsEmpty()return(root==NULL)?true:false;////////
BinTreeNode *Parent(BinTreeNode *current)/////////
return(root==NULL||root==current)?NULL:Parent(root,current);//////
BinTreeNode *LeftChild(BinTreeNode *current)////
return(current!=NULL)?current->leftChild:NULL;
BinTreeNode *RightChild(BinTreeNode *current)///////
return(current!=NULL)?current->rightChild:NULL;
int Height()return Height(root);///////
int Size()return Size(root);///////
BinTreeNode *getRoot()constreturn root;///////
void preOrder()///////
preOrder(root);
void inOrder()///////
inOrder(root);
void postOrder()///
postOrder(root);
void levelOrder()/////
levelOrder(root);
void destroy()destroy(root);;
int Leaves ()return leaves(root);
protected:
BinTreeNode *root;
T RefValue;
void CreateBinTree(BinTreeNode * &subTree);
bool Insert(BinTreeNode * &subTree,const T &x);////////
void destroy(BinTreeNode * &subTree);/////
bool Find(BinTreeNode * &subTree,const T &x);///////
BinTreeNode *Copy(BinTreeNode *orignode);///////
int Height(BinTreeNode * subTree);////////
int Size(BinTreeNode * subTree);///////
BinTreeNode *Parent(BinTreeNode *Parent,BinTreeNode *current);//////
BinTreeNode *Find(BinTreeNode * &subTree,const T &x)const;////////
void Traverse(BinTreeNode * &subTree,ostream &out);///////
void preOrder(BinTreeNode * &subTree);///////
void inOrder(BinTreeNode * &subTree);///////
void postOrder(BinTreeNode * &subTree);///////
void levelOrder(BinTreeNode *&subtree);
int leaves(BinTreeNode * &subTree);
;
#endif // !defined(AFX_BINARYTREE_H__61FEB349_65EE_40FB_82DF_25FFBCBDFC6E__INCLUDED_)
BinaryTree.cpp
// BinaryTree.cpp: implementation of the BinaryTree class.
//
//////////////////////////////////////////////////////////////////////
#include "BinaryTree.h"
#include<stdlib.h>
#include "queue.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
void BinaryTree::CreateBinTree(BinTreeNode * &subTree) /////////建立二叉树
T item;
cin>>item;
if(item!=RefValue)
subTree=new BinTreeNode(item);
if(subTree==NULL)
cerr<<"存储分配错误!"<<endl;
exit(1);
CreateBinTree(subTree->leftChild);
CreateBinTree(subTree->rightChild);
else subTree=NULL;
void BinaryTree::destroy(BinTreeNode *& subTree) ////删除二叉树
if(subTree!=NULL)
destroy(subTree->leftChild);
destroy(subTree->rightChild);
delete subTree;
BinTreeNode* BinaryTree::Parent(BinTreeNode *subTree, BinTreeNode *current) //找父母结点
if(subTree==NULL) return NULL;
if(subTree->leftChild==current||subTree->rightChild==current)
return subTree;
BinTreeNode *p;
if((p=Parent(subTree->leftChild,current))!=NULL) return p;
else return Parent(subTree->rightChild,current);
void BinaryTree::preOrder( BinTreeNode * &subTree) //前序遍历
if(subTree!=NULL)
cout<<subTree->data<<" ";
preOrder(subTree->leftChild);
preOrder(subTree->rightChild);
void BinaryTree::inOrder( BinTreeNode * &subTree) //中序遍历
if(subTree!=NULL)
inOrder(subTree->leftChild);
cout<<subTree->data<<" ";
inOrder(subTree->rightChild);
void BinaryTree::postOrder( BinTreeNode *&subTree ) // 后序遍历
if(subTree!=NULL)
postOrder(subTree->leftChild);
postOrder(subTree->rightChild);
cout<<subTree->data<<" ";
void BinaryTree::levelOrder(BinTreeNode *&subtree) //层序遍历
if(root==NULL)return;
queue<BinTreeNode*> Q;
BinTreeNode *p=root;
Q.EnQueue(p);
while(!Q.Isempty())
Q.DeQueue(p);
cout<<p->data<<" ";
if(p->leftChild)
Q.EnQueue(p->leftChild);
if(p->rightChild)
Q.EnQueue(p->rightChild);
int BinaryTree::Size(BinTreeNode *subTree) //求结点个数
if(subTree==NULL) return 0;
else return 1+Size(subTree->leftChild)+Size(subTree->rightChild);
int BinaryTree::Height(BinTreeNode *subTree) //求数的深度
if(subTree==NULL) return 0;
else
int i=Height(subTree->leftChild);
int j=Height(subTree->rightChild);
return (i>j)?i+1:j+1;
int BinaryTree::leaves(BinTreeNode * &subTree) //求叶子节点个数
if(subTree==NULL) return 0;
else if(subTree->leftChild==NULL&&subTree->rightChild==NULL)return 1;
else
int i=leaves(subTree->leftChild);
int j=leaves(subTree->rightChild);
return i+j;
主函数:
#include "BinaryTree.h"
int main_menu()
char option;
while(1)
cout<<" 主菜单"<<endl;
cout<<endl;
cout<<" 请选择操作:"<<endl;
cout<<" 1 建立树:"<<endl;
cout<<" 2 清空树"<<endl;
cout<<" 3 退出"<<endl;
cin>>option;
switch(option)
case '1':
return 1;
case '2':
return 2;
case '3':
return 3;
default:
cout<<"输入错误,请检查输入!"<<endl;
break;
int tree_menu(BinaryTree &btn)
char option;
while(1)
cout<<" 树的相关操作:"<<endl;
cout<<" 请选择操作:"<<endl;
//cout<<" 1 输入节点"<<endl;
cout<<" 2 按前序输出"<<endl;
cout<<" 3 按中序输出"<<endl;
cout<<" 4 按后序输出"<<endl;
cout<<" 5 按层序输出"<<endl;
cout<<" 6 求节点个数"<<endl;
cout<<" 7 求树的深度"<<endl;
cout<<" 8 求树的高度"<<endl;
cout<<" 9 返回主菜单"<<endl;
cin>>option;
switch(option)
// case '1':
//
// cout<<"输入节点,-1为结束标志"<<endl;
// btn.CreateBinTree();
// break;
//
case '2':
cout<<"按前序输出为:"<<endl;
btn.preOrder();
break;
case '3':
cout<<"按中序输出为:"<<endl;
btn.inOrder();
break;
case '4':
cout<<"按后序输出为:"<<endl;
btn.postOrder();
break;
case '5':
cout<<"按层序输出为:"<<endl;
btn.levelOrder();
break;
case '6':
cout<<"节点个数为:"<<btn.Size()<<endl;
break;
case '7':
cout<<"求树的深度为:"<<btn.Height()<<endl;
break;
case '8':
cout<<"求树的高度为:"<<btn.Height()<<endl;
break;
case '9':
return 9;
default:
cout<<"输入有误,请检查输入!"<<endl;
break;
int main()
bool bCreated=false;
int op;
BinaryTree btn(-1);
while(1)
op=main_menu();
switch(op)
case 1:
if(!bCreated)
cout<<"1 输入节点,-1为结束标志"<<endl;
btn.CreateBinTree();
bCreated=true;
tree_menu(btn);
break;
case 2:
btn.destroy();
bCreated=false;
break;
case 3:
return 0;
return 0;
参考技术A 其实c语言和C++在我们用数据结构的时候,可简单的区别为输入输出的区别,所以用vc6.0编是完全可以的,我们都是用vc6.0做这个实验的,代码如下://==========================================定义头部
#include <iostream>
using namespace std;
struct BiTNode
char data;
struct BiTNode *lchild, *rchild;//左右孩子
;
BiTNode*T;
void CreateBiTree(BiTNode* &T);
void Inorder(BiTNode* &T);
void PreOrderTraverse(BiTNode* &T);
void Posorder(BiTNode* &T);
//===========================================主函数
int main()
cout<<"创建一颗树,其中A->Z字符代表树的数据,用“#”表示空树:"<<endl;
CreateBiTree(T);
cout<<"先序递归遍历:"<<endl;
PreOrderTraverse(T);
cout<<endl;
cout<<"中序递归遍历:"<<endl;
Inorder(T);
cout<<endl;
cout<<"后序递归遍历:"<<endl;
Posorder(T);
cout<<endl;
return 1;
//=============================================先序递归创建二叉树树
void CreateBiTree(BiTNode* &T)
//按先序输入二叉树中结点的值(一个字符),空格字符代表空树,
//构造二叉树表表示二叉树T。
char ch;
if((ch=getchar())=='#')T=NULL;//其中getchar()为逐个读入标准库函数
else
T=new BiTNode;//产生新的子树
T->data=ch;//由getchar()逐个读入来
CreateBiTree(T->lchild);//递归创建左子树
CreateBiTree(T->rchild);//递归创建右子树
//CreateTree
//===============================================先序递归遍历二叉树
void PreOrderTraverse(BiTNode* &T)
//先序递归遍历二叉树
if(T)//当结点不为空的时候执行
cout<<T->data;
PreOrderTraverse(T->lchild);//
PreOrderTraverse(T->rchild);
else cout<<"";
//PreOrderTraverse
//================================================中序遍历二叉树
void Inorder(BiTNode* &T)//中序递归遍历二叉树
if(T)//bt=null退层
Inorder(T->lchild);//中序遍历左子树
cout<<T->data;//访问参数
Inorder(T->rchild);//中序遍历右子树
else cout<<"";
//Inorder
//=================================================后序递归遍历二叉树
void Posorder(BiTNode* &T)
if(T)
Posorder(T->lchild);//后序递归遍历左子树
Posorder(T->rchild);//后序递归遍历右子树
cout<<T->data;//访问根结点
else cout<<"";
//=================================================
这是我自己做的,有什么不好的地方,欢迎纠错本回答被提问者采纳 参考技术B #include <iostream>
#include <vector>
using namespace std;
template <typename elemType>
class BinaryTree;
template <typename elemType>
class BTnode;
template <typename valType>
ostream&
foo( ostream &os, const BTnode<valType> &bt );
template <typename valType>
class BTnode
friend class BinaryTree<valType>;
friend ostream&
// foo<valType>( ostream&, const BTnode<valType>& );
foo( ostream&, const BTnode<valType>& );
public:
BTnode( const valType &val );
const valType& value() const return _val;
int occurs() const return _cnt;
void remove_value( const valType&, BTnode*& );
void insert_value( const valType& );
bool find_value( const valType& ) const;
void preorder ( BTnode*, ostream& ) const;
void inorder ( BTnode*, ostream& ) const;
void postorder( BTnode*, ostream& ) const;
static void lchild_leaf( BTnode *leaf, BTnode *subtree );
private:
int _cnt; // occurrence count
valType _val;
BTnode *_lchild;
BTnode *_rchild;
void display_val( BTnode *pt, ostream &os ) const;
BTnode( const BTnode& );
BTnode& operator=( const BTnode& );
;
template <typename valType>
inline
BTnode<valType>::
BTnode( const valType &val )
: _val( val )
_cnt = 1;
_lchild = _rchild = 0;
template <typename valType>
void
BTnode<valType>::
insert_value( const valType &val )
if ( val == _val )
_cnt++;
(*BinaryTree<valType>::os()) << "BTnode::insert_value: increment count( "
<< val << " : " << _cnt << " )\n";
return;
if ( val < _val )
if ( ! _lchild )
_lchild = new BTnode( val );
(*BinaryTree<valType>::os()) << "ok: BTnode::insert_value at left child( " << val << " )\n";
else _lchild->insert_value( val );
else
if ( ! _rchild )
_rchild = new BTnode( val );
(*BinaryTree<valType>::os()) << "ok: BTnode::insert_value at right child( " << val << " )\n";
else _rchild->insert_value( val );
template <typename valType>
bool
BTnode<valType>::
find_value( const valType &val ) const
if ( val == _val )
return true;
if ( val < _val )
if ( ! _lchild )
return false;
else return _lchild->find_value( val );
else
if ( ! _rchild )
return false;
else return _rchild->find_value( val );
template <typename valType>
void
BTnode<valType>::
lchild_leaf( BTnode *leaf, BTnode *subtree )
while ( subtree->_lchild )
subtree = subtree->_lchild;
subtree->_lchild = leaf;
template <typename valType>
void
BTnode<valType>::
remove_value( const valType &val, BTnode *&prev )
if ( val < _val )
if ( ! _lchild )
return; // not present
else _lchild->remove_value( val, _lchild );
else
if ( val > _val )
if ( ! _rchild )
return; // not present
else _rchild->remove_value( val, _rchild );
else
// ok: found it
// reset the tree then delete this node
if ( _rchild )
prev = _rchild;
if ( _lchild )
if ( ! prev->_lchild )
prev->_lchild = _lchild;
else BTnode<valType>::lchild_leaf( _lchild, prev->_lchild );
else prev = _lchild;
delete this;
template <typename valType>
inline void BTnode<valType>::
display_val( BTnode *pt, ostream &os ) const
os << pt->_val;
if ( pt->_cnt > 1 )
os << "( " << pt->_cnt << " ) ";
else os << ' ';
template <typename valType>
void BTnode<valType>::
preorder( BTnode *pt, ostream &os ) const
if ( pt )
display_val( pt, os );
if ( pt->_lchild ) preorder( pt->_lchild, os );
if ( pt->_rchild ) preorder( pt->_rchild, os );
template <typename valType>
void BTnode<valType>::
inorder( BTnode *pt, ostream &os ) const
if ( pt )
if ( pt->_lchild ) inorder( pt->_lchild, os );
display_val( pt, os );
if ( pt->_rchild ) inorder( pt->_rchild, os );
template <typename valType>
void BTnode<valType>::
postorder( BTnode *pt, ostream &os ) const
if ( pt )
if ( pt->_lchild ) postorder( pt->_lchild, os );
if ( pt->_rchild ) postorder( pt->_rchild, os );
display_val( pt, os );
template <typename elemType>
class BinaryTree
public:
BinaryTree();
BinaryTree( const vector< elemType >& );
BinaryTree( const BinaryTree& );
~BinaryTree();
BinaryTree& operator=( const BinaryTree& );
void insert( const vector< elemType >& );
void insert( const elemType& );
void remove( const elemType& );
void clear() clear( _root ); _root = 0; // remove entire tree ...
bool empty() return _root == 0;
void inorder( ostream &os = *_current_os ) const _root->inorder( _root, os );
void postorder( ostream &os = *_current_os ) const _root->postorder( _root, os );
void preorder( ostream &os = *_current_os ) const _root->preorder( _root, os );
bool find( const elemType& ) const;
ostream& print( ostream &os = *_current_os,
void (BinaryTree<elemType>::*traversal)( ostream& ) const =
&BinaryTree<elemType>::inorder ) const;
static void current_os( ostream *os ) if ( os ) _current_os = os;
static ostream* os() return _current_os;
private:
BTnode<elemType> *_root;
static ostream *_current_os;
// copy a subtree addressed by src to tar
void copy( BTnode<elemType>*&tar, BTnode<elemType>*src );
void clear( BTnode<elemType>* );
void remove_root();
;
template <typename elemType>
ostream *BinaryTree<elemType>::_current_os = &cout;
template <typename elemType>
inline
BinaryTree<elemType>::
BinaryTree()
: _root( 0 )
template <typename elemType>
inline
BinaryTree<elemType>::
BinaryTree( const BinaryTree &rhs )
copy( _root, rhs._root );
template <typename elemType>
inline
BinaryTree<elemType>::
~BinaryTree() clear();
template <typename elemType>
inline BinaryTree<elemType>&
BinaryTree<elemType>::
operator=( const BinaryTree &rhs )
if ( this != &rhs )
clear();
copy( _root, rhs._root );
template <typename elemType>
inline void
BinaryTree<elemType>::
insert( const elemType &elem )
if ( ! _root )
(*BinaryTree<elemType>::os()) << "BinaryTree::insert: root( " << elem << " )\n";
_root = new BTnode<elemType>( elem );
else _root->insert_value( elem );
template <typename elemType>
BinaryTree<elemType>::
BinaryTree( const vector< elemType > &vec )
_root = 0;
for ( int ix = 0; ix < vec.size(); ++ix )
insert( vec[ ix ] );
template <typename elemType>
void
BinaryTree<elemType>::
insert( const vector< elemType > &vec )
for ( int ix = 0; ix < vec.size(); ++ix )
insert( vec[ ix ] );
template <typename elemType>
inline void
BinaryTree<elemType>::
remove( const elemType &elem )
if ( _root )
if ( _root->_val == elem )
remove_root();
else _root->remove_value( elem, _root );
template <typename elemType>
void
BinaryTree<elemType>::
remove_root()
if ( ! _root ) return;
BTnode<elemType> *tmp = _root;
if ( _root->_rchild )
_root = _root->_rchild;
BTnode<elemType> *lc = tmp->_lchild;
BTnode<elemType> *newlc = _root->_lchild;
// if left child of root is non-null
// attach it as leaf to left subtree
if ( lc )
if ( ! newlc )
_root->_lchild = lc;
else BTnode<elemType>::lchild_leaf( lc, newlc );
else _root = _root->_lchild;
delete tmp;
template <typename elemType>
void
BinaryTree<elemType>::
clear( BTnode<elemType> *pt )
if ( pt )
clear( pt->_lchild );
clear( pt->_rchild );
delete pt;
template <typename elemType>
ostream&
BinaryTree<elemType>::
print( ostream &os,
void (BinaryTree::*traversal)( ostream& ) const ) const
(this->*traversal)( os );
return os;
template <typename elemType>
inline ostream&
operator<<( ostream &os, const BinaryTree<elemType> &bt )
os << "Tree: " << endl;
bt.print( os, &BinaryTree<elemType>::inorder );
return os;
template <typename elemType>
inline bool
BinaryTree<elemType>::
find( const elemType &elem ) const
return ! _root
? false
: _root->find_value( elem );
template <typename elemType>
void
BinaryTree<elemType>::
copy( BTnode<elemType> *&tar, BTnode<elemType> *src )
if ( src )
tar = new BTnode<elemType>( src->_val );
if ( src->_lchild ) copy( tar->_lchild, src->_lchild );
if ( src->_rchild ) copy( tar->_rchild, src->_rchild );
#include <string>
#include <algorithm>
#include <fstream>
using namespace std;
main()
/*
BinaryTree< int > bt;
bt.insert( 7 );
bt.insert( 5 );
bt.insert( 9 );
bt.insert( 6 );
bt.insert( 3 );
*/
/*
BinaryTree< string > bt;
bt.insert( "Piglet" );
bt.insert( "Pooh" );
bt.insert( "Eeyore" );
bt.insert( "Kanga" );
bt.insert( "Tigger" );
*/
ofstream log( "logfile.txt" );
if ( ! log )
cerr << "error: unable to open file!\n";
return -1;
else BinaryTree<string>::current_os( &log );
/*
int ia[] = 24, 18, 36, 12, 14, 8, 24, 1, 42, 24, 8, 8, 16, 55 ;
vector< int > ivec( ia, ia + 14 );
BinaryTree<int> bt( ivec );
log << "preorder traversal: \n";
// cout << should see\n\t ";
bt.preorder( log );
bt.clear();
log << "\nbt is now " << ( bt.empty() ? " empty! " : " oops -- not empty!" ) << endl;
sort( ivec.begin(), ivec.end() );
bt.insert( ivec );
log << "\n\ninorder traversal:\n";
bt.inorder( log );
bt.insert( ivec );
log << "\n\npostorder traversal:\n";
bt.postorder( log );
log << endl << endl;
*/
BinaryTree<string> bt;
bt.insert( "Piglet" );
bt.insert( "Eeyore" );
bt.insert( "Roo" );
bt.insert( "Tigger" );
bt.insert( "Chris" );
bt.insert( "Pooh" );
bt.insert( "Kanga" );
log << "preorder traversal: \n";
bt.preorder( log );
log << "\n\nabout to remove root: Piglet\n";
bt.remove( "Piglet" );
log << "\n\npreorder traversal after Piglet removal: \n";
bt.preorder( log );
log << "\n\nabout to remove Eeyore\n";
bt.remove( "Eeyore" );
log << "\n\npreorder traversal after Piglet removal: \n";
bt.preorder( log );
// log << "\n\ninorder traversal:\n";
// bt.inorder( log );
// log << "\n\npostorder traversal:\n";
// bt.postorder( log );
//
return 0;
参考技术C 新建个win32控制台应用的工程,添加c++源文件, 里面有开始写程序,写完后debug,直接把你写的程序和生成的exe拷给老师就行。你写的程序叫TOY PROGRAM,只能在DOS下面跑,你理解的那个估计是要写个界面,就你现在的水平看,基本的VC都还不是很懂。所以你按照上面人说的写就是了。分就不用给了 参考技术D 比对着书上的写,书上不是有好几个例子吗,前序 中序 后序遍历 ,用递归或者普通方法都可以追问
把书上的直接写到C++程序软件里?那↑怎么输入啊?完全不会!
你能不能给个完整的C++程序让我复制粘贴到软件里就能用啊?
你问->怎么输入吗,↑是什么符号,
代码
#include "stdio.h"
#include "malloc.h"
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
typedef int Status;
typedef char ElemType;
typedef struct BiTNode
ElemType data;
struct BiTNode *lchild,*rchild;//左右孩子指针
BiTNode,*BiTree;
Status CreateBiTree(BiTree &T)
// 按先序次序输入二叉树中结点的值(一个字符),’#’字符表示空树,
// 构造二叉链表表示的二叉树T。
char ch;
scanf("%c",&ch);
if (ch=='#') T = NULL;
else
if (!(T = (BiTNode *)malloc(sizeof(BiTNode)))) return ERROR;
T->data=ch; // 生成根结点
CreateBiTree(T->lchild); // 构造左子树
CreateBiTree(T->rchild); // 构造右子树
return OK;
// CreateBiTree
Status PrintElement( ElemType e ) // 输出元素e的值
printf("%c", e );
return OK;
// PrintElement
Status PreOrderTraverse( BiTree T, Status(*Visit)(ElemType) )
if(T)
if (Visit(T->data))
if (PreOrderTraverse(T->lchild,Visit))
if (PreOrderTraverse(T->rchild,Visit)) return OK;
return ERROR;
else return OK;
// PreOrderTraverse
Status InOrderTraverse( BiTree T, Status(*Visit)(ElemType) )
if (T)
if (InOrderTraverse(T->lchild,Visit))
if (Visit(T->data))
if (InOrderTraverse(T->rchild,Visit)) return OK;
return ERROR;
else return OK;
// InOrderTraverse
Status PostOrderTraverse( BiTree T, Status(*Visit)(ElemType) )
if (T)
if (PostOrderTraverse(T->lchild,Visit))
if (PostOrderTraverse(T->rchild,Visit))
if (Visit(T->data)) return OK;
return ERROR;
else return OK;
// PostOrderTraverse
int main() //主函数
BiTree T;
CreateBiTree(T);
PreOrderTraverse(T,PrintElement);
printf("\n");
InOrderTraverse(T,PrintElement);
printf("\n");
PostOrderTraverse(T,PrintElement);
这明显是C语言麼……C++怎么写啊……我都快疯了,都看不懂,啥也不会……
我就想问出一套语句,我把它复制粘贴到程序软件里,然后交上去,就结束。
现在看来,我把你的这个复制粘贴一下,用我们用的C++的软件都不能Build,不知道为什么
还有,老师说是要做出一个程序……程序到底是什么?是一个.exe的文件?
要疯了要疯了……
C和C++对于你要实现的东西来说差别不大,程序就是编译出来一个exe,你们老师是让你们出一个黑屏类似dos界面的exe程序。光图省事,老师是让你们好好学习
这样给你一个网址http://edu.codepub.com/2009/0805/12310.php,把这里面的代码粘贴到C++里面,注意分成三个文件,.h .cpp 还有个包含main函数的文件。
以上是关于用C语言程序编一个个人所得税的源程序,求高手解答的主要内容,如果未能解决你的问题,请参考以下文章