Question

Problem Statement write a C++ program for a class of N students (Where N >3) and...

Problem Statement

write a C++ program for a class of N students (Where N >3) and the task is to find the top U marks-scorer. Write a program that will print the index of the topper of the class which will be same as the index of the student in the input array (use 0-based indexing). First print the index of the student having highest marks. If there are more than one students having same marks then print their indices in ascending order.

Input Example:

Suppose U = 2 and the students having highest marks have indices 0 and 5 and students having second highest marks have indices 6 and 7 then output will be 0 5 6 7.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program:

Sample Output:

Rawcode:

#include<iostream>
#include<algorithm>       //including algorithm header file for sort() function
using namespace std;
int Duplicates(int a[], int n)    //Duplicate() funciton removing duplicates of array
{
    int t[n];    //initializing temparary array
    int j = 0;
    for (int i=0; i<n-1; i++)
        if (a[i] != a[i+1]) //if next elements of array not equal to cuurent element
            t[j++] = a[i];    //storing in temporary array
    t[j++] = a[n-1];    //assigning main array elements to temparary array
    for (int i=0; i<j; i++)    //modifing original array
        a[i] = t[i];
    return j;
}
int main()       //main function
{
   int n;       //n for no.of students
   cout<<"enter the no.of students ";
   cin>>n;
   int arr[n],b[n],c[n];       //decleration arrays of size n
   cout<<"enter the marks of students"<<endl;
   for(int i=0;i<n;i++)       //getting marks from user
   {
       cin>>arr[i];
   }
   cout<<"array of student marks is"<<endl;  
   for(int i=0;i<n;i++)      
       {cout<<arr[i]<<" ";       //assinging marks to duplicate arra b
       b[i]=arr[i];}
   cout<<"\nenter how many top U scorers you want ";
   int u;      
   cin>>u;
   sort(b, b+n, greater<>());       //builtin funciotn sort() to sort the array in descending order
   int m=Duplicates(b,n);       //calling duplicate()
   cout<<"\nidices of top "<<u<<" scorers"<<endl;
   for(int i=0;i<u;i++)   //traversing upto u in array b
   {  
       for(int j=0;j<n;j++)   //traversing all over array of arr
       {
           if(b[i]==arr[j])   //if element of array b is in main marks array
               cout<<j<<" ";       //then prints their index
       }
   }
   cout<<endl;
}
  


------------------------------------------------

Hope you understand.If you have any doubts comment me.

Upvote me.

Thank you.

Add a comment
Know the answer?
Add Answer to:
Problem Statement write a C++ program for a class of N students (Where N >3) and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a complete C++ program that reads students names and their test scores from an input...

    Write a complete C++ program that reads students names and their test scores from an input text file. The program should output each student’s name followed by the test scores and the relevant grade in an output text file. It should also find and display on screen the highest/lowest test score and the name of the students having the highest/lowest test score, average and variance of all test scores. Student data obtained from the input text file should be stored...

  • (C++ programming) Need help with homework. Write a program that can be used to gather statistical...

    (C++ programming) Need help with homework. Write a program that can be used to gather statistical data about the number of hours per week college students play video games. The program should perform the following steps: 1). Read data from the input file into a dynamically allocated array. The first number in the input file, n, represents the number of students that were surveyed. First read this number then use it to dynamically allocate an array of n integers. On...

  • C# Write a program that takes a list of information and grades of the students of...

    C# Write a program that takes a list of information and grades of the students of a class and perform some processing. Take the following steps to write the program. The program must give the user two options such as a menu. At the beginning of the program must ask the following from the user: Which task you want to do (choose an option between 1-2), 1- Entering new information 2- Searching a student If the user types something rather...

  • Write a C++ program that asks user number of students in a class and their names....

    Write a C++ program that asks user number of students in a class and their names. Number of students are limited to 100 maximum. Then, it will ask for 3 test scores of each student. The program will calculate the average of test scores for each student and display with their names. Then, it will sort the averages in descending order and display the sorted list with students’ names and ranking. Follow the Steps Below Save the project as A4_StudentRanking_yourname....

  • ONLY REQUIRE C Problem statement: You are to write a program that manages student marks for...

    ONLY REQUIRE C Problem statement: You are to write a program that manages student marks for a class. Student marks are stored as a 2D array. Each row represents the marks of one student. Each column represents one assessment. For example, if we have two students and 3 assessment items with the marks for student1 being (67.6,88.5, 75.4} and student2 being (77.5, 76.2,78.3} our 2D array would look like: 67.6, 38.5,75.4 77.5, 76.2,78.3 You are to write a script/main function...

  • Write a C++ program to : Create array arr1 of size 10 Assign values to elements...

    Write a C++ program to : Create array arr1 of size 10 Assign values to elements such that - say index = i, arr1[i] = 10 - i. Print arr1 Create arr2 and copy alternate elements from arr1 starting from index 1. Print arr2. Sort arr1 in ascending array and print its elements from indices 3 to 8 Print every output on a different line and separate array elements by spaces.

  • In Java programming language Please write code for the 6 methods below: Assume that Student class...

    In Java programming language Please write code for the 6 methods below: Assume that Student class has name, age, gpa, and major, constructor to initialize all data, method toString() to return string reresentation of student objects, getter methods to get age, major, and gpa, setter method to set age to given input, and method isHonors that returns boolean value true for honors students and false otherwise. 1) Write a method that accepts an array of student objects, and n, the...

  • Your friend Raphael is an elementary school teacher. He has n students in his class, numbered...

    Your friend Raphael is an elementary school teacher. He has n students in his class, numbered 1,2,...,n. On a particularly chilly Wednesday, he decides to lure his students into attending his class by giving away candies to each of them. However, some children are mischievous and take more candies than allotted. The students who get lesser candies thus get sad, and need to be comforted. Therefore, Raphael wants your help in determining the index of the student who is the...

  • Write a C++ Program that reads in a file containing the names of the students in...

    Write a C++ Program that reads in a file containing the names of the students in the class into an array of string elements. The program should use the random number generator to shuffle the order of the student names in the array and create pairs of students as final project team assignments. If the number of students is an odd number, then one of the groups should have a third team member.

  • c program Your teacher want to find out who is the most hardworking student in class!...

    c program Your teacher want to find out who is the most hardworking student in class! They want to input the names according to the order they fell asleep, then print their names in the reverse order. Although you can create an array large enough to store all names, your teacher don’t want to waste our precious memory! The first line of the input is an integer x, which indicate the number of students in class. Then there are x...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT