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

📄 1.cpp

📁 点歌系统的实现 有菜单显示
💻 CPP
字号:
#include <iostream.h>
#include <string.h>
#include <iomanip.h>//setw()
/////////////////////////////////////////
typedef struct song
{char name[20];
int No;
char song_name[20];
int vote_number;
}SONG;
/////////////////////////////////////////
int input(SONG []);
int menuitem(void);
void display(void);
void browse(SONG [],int);
void vote(SONG [],int);
void top3(SONG [],int);
/////////////////////////////////////////
void main()
{  SONG a[10];
   int b=menuitem();
   int n;

      while(b!=0)
	  {
         switch(b)
		 {case 1: 
		 //input the information
		        n=input(a);
		       break;
		 
          case 2:
			   browse(a,n);
			   break;
          case 3:
               top3(a,n);
		   	   break;
		  case 4:
			   vote(a,n);
			   break;
			   
         
		 }
        b=menuitem();
	  }
}
/////////////////////////////////////////
int menuitem(void )
{    display();
     int a;
     do{
        cout<<"input your choice(0 to end):"<<endl;
        cin>>a;
	 }
	 while(a<0||a>4);
return a;
}

/////////////////////////////////////////
void display(void)
{cout<<"=============menu================"<<endl;
cout<<"1:input:"<<endl;
cout<<"2:browse:"<<endl;
cout<<"3:print top 3:"<<endl;
cout<<"4:vote:"<<endl;
cout<<"0:exit:"<<endl;

}
/////////////////////////////////////////
int input(SONG s[])
{int i=0;
 char ch='y';
 
    while(ch=='y')
	{cout<<"input the name:"<<endl;
	cin>>s[i].name;
	cout<<"input the song name:"<<endl;
    cin>>s[i].song_name;
	//	cin.getline(s[i].song_name,sizeof(s[i].song_name),'\n');
	cout<<"input the No:"<<endl;
	cin>>s[i].No;
	s[i].vote_number=1;
	cout<<"input y to continue ,n to stop"<<endl;
	cin>>ch;
	i++;
	}
	return i;
}
/////////////////////////////////////////
   void browse(SONG a[],int n)
   {
	   for(int j=0;j<n;j++)
	   {cout<<setw(10)<<a[j].No<<setw(10)<<a[j].name<<setw(10)<<a[j].song_name<<setw(10)<<a[j].vote_number<<endl;}
   }
/////////////////////////////////////////
   void vote(SONG a[],int n)
   {  int num;
	   cout<<"input your choice(the No of the song 1~"<<n<<")"<<endl;
       cin>>num;
	   a[num-1].vote_number++;
   }
/////////////////////////////////////////排序并输出前3
   void top3(SONG a[],int n)
  { SONG temp;
   int i,j;
	   for( i=n-1;i>0;i--)
        for ( j=0;j<i;j++)
		if(a[j].vote_number<a[j+1].vote_number)
		{
			temp=a[j];
		    a[j]=a[j+1];
	    	a[j+1]=temp;
		}

		for(j=0;j<3;j++)
			cout<<a[j].No<<" "<<a[j].name<<" "<<a[j].song_name<<" "<<a[j].vote_number<<endl;

		
  
   
   }

⌨️ 快捷键说明

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