Tìm thấy 8 mục

life_single2610

Giúp mình chút - 14/12/2009, 21:48

Đâ là đề thầy cho , các bạn giúp mình làm 2 case cuối cùng nhé , mình làm hoài ma ko ra:
1.xuất cây NPTK các số nguyên, tính tổng các giá trị nguyên tố.
2.xuất cây NPTK các số nguyên, tính tổng các giá trị chính phương.
Làm như bên c cơ bản thì dễ , nhưng với Nhị Phân thì mình bó tay , ai giúp minh nhanh nhé.cảm ơn nhìu

life_single2610

Giúp mình chút - 14/12/2009, 21:43

Code:
#include<stdio.h>
#include<conio.h>

typedef  struct tagTNode
{
   int Key;
   struct tagTNode* pLeft;
   struct tagTNode* pRight;
}TNODE;
typedef  TNODE* TREE;
void initTree(TREE &T)
{
   T=NULL;
}
TNODE* GetNode(int x)
{
   TNODE* p=new TNODE;
   if(p==NULL)   
      return p;
   p->Key=x;
   p->pLeft=p->pRight=NULL;
   return p;
}
int ThemNut(TREE &T, int x)
{
   if(T!=NULL)
   {   if(x==T->Key)    
         return 0;
      else
      {
         if(x<T->Key)   
            ThemNut(T->pLeft, x);
         else       
            ThemNut(T->pRight, x);
      }
   }
   else
   {
      T=new TNODE;
      if(T==NULL)    
         return -1;
      T->Key=x;
      T->pLeft=T->pRight=NULL;
      return 1;
   }
}



int SearchNode(TREE &T,int X)
{
   if(T!=NULL)
   {
      if(T->Key==X)   
         return 1;
      if(T->Key>X)      
         return SearchNode(T->pLeft,X);
      else         
         return SearchNode(T->pRight,X);
   }
   return 0;
}



/*
TNODE* SearchNode(TREE T,int x)
{
   if(T!=NULL)
   {
      if(T->Key==x)  return T;
      if(x<T->Key)
         return SearchNode(T->pLeft,x);
      else
         return SearchNode(T->pRight,x);
   }
   //return T;
}
*/
void SearchStandFor(TREE &p, TREE &q)
{
   if(q->pLeft)
      SearchStandFor(p,q->pLeft);
   else
   {
      p->Key=q->Key;
      p=q;
      q=q->pRight;
   }
}
int Max(int &a,int &b)
{
   if(a>b)
      return a;
   else
      return b;
}
int DoCaoCay(TREE T)
{
   //int Max;
   if(T)
   {
      int T1=DoCaoCay(T->pLeft);
      int T2=DoCaoCay(T->pRight);
      return Max(T1,T2)+1;
   }
   else
      return 0;
}

int  DelNode(TREE &T, int x)
{
   if(T==NULL)      
      return 0;
   if(T->Key>x)      
      return DelNode(T->pLeft,x);
   if(T->Key<x)   
      return DelNode(T->pRight,x);
   else
   {
      TNODE*p=T;
      if(T->pLeft==NULL)
         T=T->pRight;
      else if(T->pRight==NULL)
         T=T->pLeft;
      else
      {
      
         TNODE* q=T->pRight;
         SearchStandFor(p,q);
      }
   delete p;
   }
return 1;
}
void  RemoveTree(TREE &T)
{
   if(T)
   {
      RemoveTree(T->pLeft);
      RemoveTree(T->pRight);
      delete T;
   }
}
int DemNutLa(TREE T)
{
   if(T!=NULL)
   {
   
   if(T->pLeft==NULL && T->pRight==NULL)
          return 1;
      else
          return DemNutLa(T->pLeft)+DemNutLa(T->pRight);
   }

   else
      return 0;
}
int DEMNODE(TREE &T)
{
    if(T==NULL)
       return 0;
    return (1+DEMNODE(T->pLeft)+DEMNODE(T->pRight));
}
void sapxep(TREE &T)
{
   
}
void XuatCay(TREE &T)
{
   if(T!=NULL)
   {
    printf("%4d",T->Key);
    XuatCay(T->pLeft);
    XuatCay(T->pRight);
   }
}

int DEMNODECHAN(TREE &T)
{
   int idem=0;
    if(T==NULL)
       return 0;
   if(T->Key%2==0)
      return (1+DEMNODECHAN(T->pLeft)+DEMNODECHAN(T->pRight));
   
   
   
}

int TongChan(TREE &T)
{
   int S=0;
   
   if(T==NULL)
      return S;
   if(T!=NULL)
   {
       if(T->Key>0&&T->Key%2==0)
     S=S+T->Key;
    
    S+=TongChan(T->pLeft);
    S+=TongChan(T->pRight);
   }
   return S;
   
}
int TongLe(TREE &T)
{
   int S=0;
   if(T==NULL)
      return S;
   if(T!=NULL)
   {
       if(T->Key>0&&T->Key%2!=0)
     S=S+T->Key;
    S+=TongLe(T->pLeft);
    S+=TongLe(T->pRight);
   }
   return S;
}
int TONGNODE(TREE &T)
{
    if(T==NULL)
    return 0;
       return(T->Key+TONGNODE(T->pLeft)+TONGNODE(T->pRight));
}


void CreateTree(TREE &T)
{
   int x;
   do
   {
   nhap:
         printf("\nNhap vao key:");
         printf("x=");
         scanf("%d",&x);
         if(x<0)
         {
            printf("\n Ban Phai Nhap So >0!! Nhap lai:");
            goto nhap;
         }
         if(x==0)   
             break;
   int kq=ThemNut(T,x);
   if(kq==-1) break;
   else if(kq==0)   
      printf("\nDa co trong danh sach");
   }while(1);
}
void NLR(TREE &T)
{
   if(T!=NULL)
   {
      printf("%4d",T->Key);
      NLR(T->pLeft);
      NLR(T->pRight);
   }
}
void LNR(TREE &T)
{
   if(T!=NULL)
   {
      LNR(T->pLeft);
      printf("%4d",T->Key);
      LNR(T->pRight);
   }
}
void LRN(TREE &T)
{
   if(T!=NULL)
   {
      LRN(T->pLeft);
      LRN(T->pRight);
      printf("%4d",T->Key);
   }
}
void xuat(TREE &T)
{
   if(T==NULL)
   return;
   xuat(T->pLeft);     
   printf("%4d",T->Key);       
   xuat(T->pRight);
}
void XuatChan(TREE &T)
{   
   if(T==NULL)               
   return;       
   XuatChan(T->pLeft);       
   if(T->Key%2==0)   
   {         
       printf("%4d",T->Key);       
       
   }
    XuatChan(T->pRight);
   
}
void Xuatle(TREE &T)
{   
   if(T==NULL)               
   return;       
   Xuatle(T->pLeft);       
   if(T->Key%2!=0)   
   {         
       printf("%4d",T->Key);       
       
   }
    Xuatle(T->pRight);
   
}
void main()
{
   TREE  T;
   int x;
   initTree(T);
   int chon;
   do
   {
      printf("\n______________-Cay Nhi Phan-______________");
      printf("\n    1.Nhap cay nhi phan                  ");
      printf("\n    2.Duyet theo cac phan tu co trong cay");
      printf("\n    3.Kiem tra so x                      ");
      printf("\n    4.Dem so node co trong cay          ");
      printf("\n    5.Dem so nut la co trong cay        ");
      printf("\n    6.Tong Node                          ");
      printf("\n    7.Do cao cay                        ");
      printf("\n    8.Them Node vao Key                  ");
      printf("\n    9.Xuat phan tu chan                ");
      printf("\n    10.XuAT Phan tu le                  ");
      printf("\n    11.Tong Chan                        ");
      printf("\n    12.Tong Le                          ");
      printf("\n    13.Sap xep tang dan                  ");
      printf("\n__________________________________________");
      printf("\nMoi ban chon:");
      scanf("%d",&chon);
      switch(chon)
      {
         case 1:
            printf("Khoi tao cay:");
            printf("\nNhap phim 0 de dung nhap:");
            CreateTree(T);
            printf("\ncay da da dc tao:");
            break;
         case 2:
            printf("\n__________Duyet Danh sach_______________\n");         
            char chon1;               
               printf("\n_____Cac PT duyet_____");
               printf("\n__a.Node-left-right___");
               printf("\n__b.Left-Node-right___");
               printf("\n__c.Left-Right-Node___");
               printf("\n______________________");
               printf("\nMoi ban chon:");
               scanf("%s",&chon1);
               switch(chon1)
               {
                  case 'a':
                     printf("\nDa duyet theo NLR:\n");
                     NLR(T);
                     break;
                  case 'b':
                     printf("\nDa duyet theo LNR:\n");
                     LNR(T);
                     break;
                  case 'c':
                     printf("\nDa duyet theo LRN:\n");
                     LRN(T);
                  break;
               }
            
            break;
         case 3:
            printf("\nTim node");
            printf("\nNhap vao so muon tim:");
            scanf("%d",&x);
            if(SearchNode(T,x)==0)
               printf("\n Khong co trong cay");
            else
               printf("\n so %d co trong cay",x);
            break;
         case 4:
            printf("\nDem so Node:");
            printf("\nCay co:%5d node ",DEMNODE(T));
            break;
         case 5:
            printf("\nDem so nut la co trong cay:___");
            printf("\nSo nut la : %d",DemNutLa(T));
            break;
         case 6:
            printf("\nTong tat ca cac node trong cay la: %d",TONGNODE(T));
            break;
         case 7:
            printf("\nDO caO CUA CAY:");
            printf("\nDo cao cua cay la:%d",DoCaoCay(T));
            break;
         case 8:
            printf("\nNhap vao so them vao cay:");
            scanf("%d",&x);
            ThemNut(T,x);   
            NLR(T);
            break;         
         case 9:
            XuatChan(T);
            break;
         case 10:
            Xuatle(T);
            break;
         case 11:
            printf("\nTong Chan:%d",TongChan(T));
            break;
         case 12:
            printf("\nTong Le:%d",TongLe(T));
            break;
         case 13:
               xuat(T);
               break;
         case 0:
            break;
            
      }
   }while(chon!='0');
   getch();
   return 0;
}




life_single2610

Quan ly nhan vien - 11/12/2009, 20:54

Code:
using System;
using System.Collections.Generic;
using System.Text;

namespace NHANVIEN
{
    public class nguoi
    {
        private string _hoten, _diachi, _cmnd;
        public nguoi()
        {
            this._hoten = " ";
            this._diachi = " ";
            this._cmnd = " ";
        }
        public nguoi(string hoten, string diachi, string cmnd)
        {
            this.hoten = _hoten;
            this.diachi = _diachi;
            this.cmnd = _cmnd;
        }
        public string hoten
        {
            get
            {
                return _hoten;

            }
            set
            {
                _hoten = value;

            }

        }
        public string diachi
        {
            get
            {
                return _diachi;
            }
            set
            {
                _diachi = value;
            }
        }
        public string cmnd
        {
            get
            {
                return _cmnd;
            }
            set
            {
                _cmnd = value;
            }
        }
        public string tostring()
        {
            return "\nname: " + _hoten + "\ndia chi: " + _diachi + "\nSo CMND: " + _cmnd;
        }
    }
    public class nhanvien : nguoi
    {
        private string _manv, _bophan;
        private long _luong;
        public nhanvien()
        {
            this._manv = " ";
            this._bophan= " ";
            this._luong = 0;
        }
        public nhanvien(string manv, string bophan, string luong)
        {
            this.manv= _manv;
            this.bophan=_bophan;
            this.luong=_luong;
        }
        public string manv
        {
            get
            {
                return _manv;
            }
            set
            {
                _manv = value;
            }

        }
        public string bophan
        {
            get
            {
                return _bophan;
            }
            set
            {
                _bophan = value;
            }

        }
        public long luong
        {
            get
            {
                return _luong;
            }
            set
            {
                if (value > 0)
                    _luong = value;
            }

        }
        public string tostring1()
        {
            return base.tostring() + "\nma nhan vien :" + manv + "\nMa bo phan:" + bophan + "\nLuong: " + luong;
        }
    }
    public class lanhdao : nhanvien
    {
        private string _chucvu;
        private long _phucap;
       
        public lanhdao()
        {
            this._chucvu = " ";
            this._phucap = 0;
        }
        public lanhdao(string chucvu, string phucap)
        {
            this.chucvu= _chucvu;
            this.phucap=_phucap;
        }
        public string chucvu
        {
            get
            {
                return _chucvu;
            }
            set
            {
                _chucvu = value;
            }

        }
        public long phucap
        {
            get
            {
                return _phucap;
            }
            set
            {
                if (value > 0)
                    _phucap = value;
            }
        }
   
        public string tostring3()
        {
            return base.tostring1() + "\nchuc vu:" + _chucvu + "\nPhu cap: " + _phucap + "\nTong luong :" + (base.luong + _phucap);
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("nhap vao so nhan vien ");
            int n = Convert.ToInt32(Console.ReadLine());
            nguoi[] a = new nguoi[n];
            Console.WriteLine("___Lop Nguoi_____");
            for (int i =0; i <n; i++)
            {
                Console.WriteLine("\nNhap nhan vien thu {0}",i+1);
                a[i] = new nguoi();
                Console.WriteLine("\nNhap ho ten:");
                a[i].hoten =Console.ReadLine();
                Console.WriteLine("nhap dia chi:");
                a[i].diachi =Console.ReadLine();
                Console.WriteLine("nhap cmnd:");
                a[i].cmnd = Console.ReadLine();
             
            }
            Console.WriteLine("_______________________________");
            for (int i =0; i < n; i++)
            {
                Console.WriteLine("Thong tin Nv: {0} ", i + 1);
                Console.WriteLine("{0}", a[i].tostring());
            }
            Console.WriteLine("_______________________________");
           
            Console.WriteLine("__Lop Nhan vien__");
            nhanvien[] b = new nhanvien[n];
            for (int i = 0; i < n; i++)
            {
                Console.WriteLine("\nNhap nhan vien thu {0}", i+1);
                b[i] = new nhanvien();
                Console.WriteLine("\nNhap ho ten:");
                b[i].hoten =Console.ReadLine();
                Console.WriteLine("nhap dia chi:");
                b[i].diachi =Console.ReadLine();
                Console.WriteLine("nhap cmnd:");
                b[i].cmnd = Console.ReadLine();
                Console.WriteLine("nhap ma nhan vien:");
                b[i].manv = Console.ReadLine();
                Console.WriteLine("nhap bo phan:");
                b[i].bophan = Console.ReadLine();
                Console.WriteLine("nhap luong:");
                b[i].luong = long.Parse(Console.ReadLine());

            }
            Console.WriteLine("_______________________________");
            for (int i =0; i <n; i++)
            {
                Console.WriteLine("Thong Tin Nv :{0} ", i + 1);
                Console.WriteLine("{0}", b[i].tostring1());
            }
            Console.WriteLine("_______________________________");
         
            lanhdao[] c = new lanhdao[n];
            Console.WriteLine("__lop Lanh dao_");
            for (int i = 0; i < n; i++)
            {
                Console.WriteLine("\nNhap nhan vien thu {0}", i + 1);
                c[i] = new lanhdao();
                Console.WriteLine("\nNhap ho ten:");
                c[i].hoten =Console.ReadLine();
                Console.WriteLine("nhap dia chi:");
                c[i].diachi = Console.ReadLine();
                Console.WriteLine("nhap cmnd:");
                c[i].cmnd =Console.ReadLine();
                Console.WriteLine("nhap ma nhan vien:");
                c[i].manv =Console.ReadLine();
                Console.WriteLine("nhap bo phan:");
                c[i].bophan =Console.ReadLine();
                Console.WriteLine("\nNhap vao chuc vu:");
                c[i].chucvu = Console.ReadLine();
                Console.WriteLine("\nNhap vao phu cap:");
                c[i].phucap = long.Parse(Console.ReadLine());
                Console.WriteLine("nhap luong:");
                c[i].luong = long.Parse(Console.ReadLine());

            }
            Console.WriteLine("_______________________________");
            for (int i = 0; i < n; i++)
            {
                Console.WriteLine("Thong Tin Nv :{0} ", i + 1);
                Console.WriteLine("{0}", c[i].tostring3());
            }
            Console.WriteLine("_______________________________");
            Console.ReadLine();
        }
    }
}

life_single2610

Quản lý tiền lương - 5/12/2009, 00:08

hì , tại mình không thấy ban set get thông tin về connguoi nên mình có chút thắc mắc đó mà .hì hì

life_single2610

Quản lý tiền lương - 4/12/2009, 22:43

đương nhiên rùi, mình cũng đang làm , chắc mình sẽ làm dc , Very Happy

life_single2610

Quản lý tiền lương - 4/12/2009, 22:09

mình mới năm 2 nên con ngố lắm , mình định làm theo hướng này , mình làm đơn giản thôi, bạn giúp mình làm đồ án nhé , cảm ơn bạn nhiều

life_single2610

Quản lý tiền lương - 4/12/2009, 22:05

hihi, bạn có code cho phép nhập thông tin tùy ý không , mình đang sửa lại code của bạn cho phép nhập , nhưng con ít lỗi chưa xong , khi nào xong mình post lên . bọn mình đang làm đồ án bài này nè , bạn có cho mình xin nhé , cảm ơn bạn nhé

life_single2610

Quản lý tiền lương - 4/12/2009, 21:18

cảm ơn bạn nhé , bài của bạn rất hay, cho mình xin yahoo lam wen nhé


Về Đầu Trang

Hôm nay: 20/5/2012, 19:32