⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 score.cpp

📁 学生成绩管理系统质量高而且本站没有的源码
💻 CPP
字号:
#ifndef _SCORE_H_
#define _SCORE_H_

#include "stdafx.h"
#include "score.h"
//#include  <iostream>
//#include  <cstdlib>
//#include  <stdlib.h>   
//#include  <stdio.h> 
//#include <string>

Score::Score()
{
	end= new ScoreNode;
	head=new ScoreNode;
	head->prior=NULL;
	head->next=end;
	end->prior=head;
	end->next=NULL;

	int lengh=0;
}            //链表构造函数

Score::~Score()
{
	Erase();
}
//析构函数

void Score::Erase()
{
	ScoreNode *current=head;
	while(current!=NULL)
	{
		head=head->next;
		delete current;
		current=head;
	}
	length=0;
}//清空链表


void Score::Product(ScoreNode *newnode,int i)
{	ScoreNode *currentl=head;
	while(currentl->next!=end)
	{
		currentl=currentl->next;
	}
	currentl->next=newnode;
	newnode->prior=currentl;
	newnode->next=end;
	end->prior=newnode;
	length++;
switch (i)
	{
    case 0:	AfxMessageBox("Add successfully!");
			break;
	case 1:	AfxMessageBox("Modify successfully!");
			break;
	case 2:	{
				ordernumber(1);
		    AfxMessageBox("insert successfully!");
				break;}
	case 3: {
				break;
			}
}

}
/*if(i==1)
	{
		head->next=newnode;
	end->prior=newnode;
	newnode->next=end;
	newnode->prior=head;
	currentl=newnode;
	length++;
	AfxMessageBox("Add successfully!");
	}
	else
	{
		{for(int k=1;k<=i-1;k++)
		{currentl=currentl->next;}
		currentl->next=newnode;
		newnode->prior=currentl;
		newnode->next=end;
		end->prior=newnode;
		length++;
	    AfxMessageBox("Add successfully!");
		}*/
//顺序插入链表

int Score::GetLength()
{
return length;

}


//得到链表长度

bool Score::IsEmpty()const
{
	return length==0;
}
//判断链表是否为空


ScoreNode* Score::Gethead()
{
	return head;
	AfxMessageBox(head->next->data.name+"wsfw");
}

ScoreNode* Score::GetEnd()
{
	return end;
	AfxMessageBox(head->next->data.name+"wsfw");
}
/*
bool Score::Find(int k,Data&x)const
{
	if(length==0)
	{
		throw exception("Score is empty!");
	}
	else if(k<1||k>length)
	{
		throw exception("no find the position of k!");
	}

	ScoreNode *current=head->next;//
	for(int i=1;(i<k)&&current;++i)//
	{
		current=current->next;
	}

	if(current)
	{
		x=current->data;//
		return true;
	}

	return false;
}*///按序号查照节点

int Score::Searchname(CString x)const
{
	int nIndex=1;
	ScoreNode *current=head->next;
    while(current&&((current->data).name!=x))
	{++nIndex;
	current=current->next;
	}

	if(current)
	{
		return nIndex;
	}

	return -1;
}

int Score::Searchnumber(CString x)const
{
	int nIndex=1;
	ScoreNode *current=head->next;
    while(current&&((current->data).number)!=x)
	{++nIndex;
	current=current->next;
	}

	if(current)
	{
		return nIndex;
	}

	return -1;
}


Score& Score::Delete(int k)

{
	if(length==0)
	{
		throw exception("ScoreNode is empty!");
	}
	else if(k<1 || k>length)
	{
        throw exception("no find the position of k, so can't delete!");
	}

	ScoreNode *current = head->next; 
    for (int i=1; (i<k)&&current; ++i)
	{
     current = current->next;
	}

    ScoreNode * p = current;
    if(current->next!=NULL)
	{
		current->prior->next = current->next;
    current->next->prior = current->prior;
	delete p;
     p = NULL;
     --length;
	}
	else
	{
		current->prior->next = current->next;
		delete p;
        p = NULL;
        --length;
	}
    //x = p->data;
    

     return *this;
}


Score& Score::Insert(int k,const Data&x)
{
	if (k>=0 && k<= length)
 {
  ScoreNode *newNode = new ScoreNode;
  newNode->data = x;

  ScoreNode *current = head;
  for (int i=0; i<k; ++i)
  {
   current = current->next;
  }

  newNode->prior = current;
  newNode->next = current->next;
  current->next->prior = newNode;
  current->next = newNode;
  
  
  ++length;
 }
 else
 {
  throw exception("no find the position of k, so can't insert!");
 }

 return *this;
}//按序号插入结点



 /*void Score::output(ostream& out)const
{
 ScoreNode *current = head->next;
 while (current!=end)
 {
  out << current->data << " ";
  current = current->next;
 }
}


ostream& operator<< (ostream& out, const Score& x)
{
 x.output(out);
 return out;
}
*/

ScoreNode* Score::Getscorenode(int k)
{
	ScoreNode* current=0;
	current=head;
	for(int i=1;i<=k&&current;i++)
		{
		current=current->next;
	}
	return current;
}

	//按序号返回结点

void Score::ordernumber(int k)
{
int i;	
//	int len=scoreo.GetLength();
	ScoreNode *ordernode=0;
	ScoreNode *currentnode=0;
	ScoreNode *tempnode=0;
//currentnode=head->next;
//ordernode=head->next;
switch (k)
{case 1:
	{	
		for(i=1;i<=length;i++)
		{	ordernode=head->next;
			currentnode=ordernode->next;
			while(currentnode!=end)
			{	
				if(((currentnode->data).number)<=((ordernode->data).number))
				{
					
					ordernode->prior->next=currentnode;
					currentnode->prior=ordernode->prior;
					ordernode->next=currentnode->next;
					ordernode->prior=currentnode;
					
					currentnode->next->prior=ordernode;
					currentnode->next=ordernode;
				
					currentnode=ordernode->next;
						
				}
			   else
			   {
				 ordernode=ordernode->next;
				   currentnode=currentnode->next;
			   }
			}
			   
		}	
		
	

	break;
	}

case 2:
	{	
		for(i=1;i<=length;i++)
		{	ordernode=head->next;
			currentnode=ordernode->next;
			while(currentnode!=end)
			{	
				if(((currentnode->data).result)<=((ordernode->data).result))
				{
					ordernode->prior->next=currentnode;
					currentnode->prior=ordernode->prior;
					ordernode->next=currentnode->next;
					ordernode->prior=currentnode;
					
					currentnode->next->prior=ordernode;
					currentnode->next=ordernode;
				
					currentnode=ordernode->next;
				}
			   else
			   {
				 ordernode=ordernode->next;
				   currentnode=currentnode->next;
			   }
			}
			   
		}	
	break;
	}
}
}

int Score::tongji(int m)
	{
		ScoreNode *current=0;
		current=head->next;
		int s=0;
	while(current!=end)
	{
		if((current->data).result>=m)
		{
			s++;
			current=current->next;
		}
		else
		{
			current=current->next;
		}
	}
		return s;
	
}




/*void Score::Swap(ScoreNode &a,ScoreNode &b)
{
	ScoreNode temp=a;
	a=b;
	b=temp;
}*/

bool Score::save(int i,int m,int n)
{
	ScoreNode *currentnodes=NULL;
	currentnodes=Getscorenode(i);
	if	 ((atoi(currentnodes->data.result)>m)&&(atoi(currentnodes->data.result)<=n))
    return true;
	else
		return false;
}	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -