Can anyone help me to transfrom the code to PYTHON code? Thanks a lot

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Can anyone help me to transfrom the code to PYTHON code? Thanks a lot

 

#include<bits/stdc++.h>
using namespace std;
void add(string name[],int scores[],string n,int sc)
{
    for(int i=0;i<10;i++)
    {
        if(scores[i]<=sc)
        {
      
        
        for(int j=9;j>i;j--)
            {
                     
                   
            
                name[j]=name[j-1];
                scores[j]=scores[j-1];
                
            }
            name[i]=n;
            scores[i]=sc;
            return;
        }
        else if(scores[i]==-1)
        {
            name[i]=n;
            scores[i]=sc;
            return;
        }
    }
}
void print(string name[],int scores[])
{
    for(int i=0;i<10;i++)
    {
        if(scores[i]!=-1)
        {
            cout<<name[i]<<"  "<<scores[i]<<"\n";
        }
    }
}
int getHscore(string name[],int scores[],string n)
{
    int ans=-1;
    for(int i=0;i<10;i++)
    {
        if(scores[i]!=-1)
        {
            if(name[i]==n)
            {
                ans=max(ans,scores[i]);
            }
        }
    }
   return ans;
}
void removeHscore(string name[],int scores[],string n)
{
    for(int i=0;i<10;i++)
    {
        if(scores[i]!=-1)
        {
            if(name[i]==n)
            {
                 for(int j=i;j<9;j++)
                 {
                     scores[j]=scores[j+1];
                     name[j]=name[j+1];
                 }
                 return;
            }
        }
        
    }
}
int main()
{
    string name[10];
    int scores[10];
    memset(scores,-1,sizeof(scores));
    while(1)
    {
        cout<<"\nTo add a new player and score enter 1\n";
        cout<<"To print the top 10 names and scores to the screen sorted by score with the highest score first enter 2\n";
        cout<<"To get a player's highest score enter 3\n";
        cout<<"To remove a player's highest score enter 4\n";
        cout<<"To quit the program enter any other number\n";
        int val;
        cin>>val;
        if(val==1)
        {
            string pname;
          cout<<"Enter player's name: ";
          cin.ignore();
          getline(cin,pname);
          
        //   cin>>pname;
          cout<<"Enter player's score: ";
          int pscore;
 
          cin>>pscore;
          add(name,scores,pname,pscore);
        }
        else if(val==2)
        {
            cout<<"\nList of Players and their scores:\n";
                print(name,scores);
                cout<<"\n\n";
        }
        else if(val==3)
        {
            cout<<"Enter player's name: ";
            string pname;
             cin.ignore();
          getline(cin,pname);
            int k=getHscore(name,scores,pname);
            if(k==-1)
            {
                cout<<"\n\nNo such player found\n\n";
            }
            else
            {
                cout<<"\n\nhighest score of entered player is "<<k<<"\n\n";
            }
        }
        else if(val==4)
        {
            cout<<"\nEnter player's name: ";
            string pname;
              cin.ignore();
          getline(cin,pname);
            removeHscore(name,scores,pname);
            cout<<"\n";
        }
        else
        {
            break;
        }
    }
    return 0;
}

Expert Solution
steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY