Question

Write a program in C++ to: 1. Read up to 10 names and 10 test scores...

Write a program in C++ to:

1. Read up to 10 names and 10 test scores from the keyboard (provide a method to end the input) (2 points);

2. print out the names and scores in a two column format (2 points);

3. use the function sort (you have to develop one) to sort the list according to test scores(4 points);

4. print out the sorted names and scores in a two column format (2 points)

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

#source code in c++:

#include <iostream>

#include <cstring>

using namespace std;

void dataPrint(string names[],int scores[]){

for(int i=0;i<10;i++){

cout<<names[i]<<"\t"<<scores[i]<<endl;

}

}

void dataSort(string names[],int scores[]){

for(int i=0;i<10;i++){

for(int j=0;j<10;j++){

if(scores[i]>scores[j]){

int t=scores[i];

scores[i]=scores[j];

scores[j]=t;

string s=names[i];

names[i]=names[j];

names[j]=s;

}

}

}

}

int main(){

string names[10];

int scores[10];

for(int i=0;i<10;i++){

cin>>names[i];

cin>>scores[i];

}

dataPrint(names,scores);

dataSort(names,scores);

cout<<"\nAfter sort:"<<endl;

dataPrint(names,scores);

return 0;

}

#output:

user@user-Latitude - 3490:-/Desktop$ g++ 1.cpp user@user-Latitude - 3490:-/Desktop$ ./a.out 51 45 S2 89 53 56 54 67 S5 98 s5

#if you have any doubt or more information needed comment below...i will respond as possible as soon..thanks...

Add a comment
Know the answer?
Add Answer to:
Write a program in C++ to: 1. Read up to 10 names and 10 test scores...
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
  • C++ Program 1. Read data for names and weights for 15 people. 2. Your program will...

    C++ Program 1. Read data for names and weights for 15 people. 2. Your program will build a list for the data maintained in ascending order based on both name and weight via a doubly linked list. 3. This dll will use one pointer to keep weights in sorted order, and use the other link to keep names on sorted order. 4. You need to build the list as you go maintaining this ordering, so at any time a print...

  • C++ Program 1. Read data for names and weights for 15 people. 2. Your program will...

    C++ Program 1. Read data for names and weights for 15 people. 2. Your program will build a list for the data maintained in ascending order based on both name and weight via a doubly linked list. 3. This dll will use one pointer to keep weights in sorted order, and use the other link to keep names on sorted order. 4. You need to build the list as you go maintaining this ordering, so at any time a print...

  • 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...

  • Write a program in C++ to: 1. Read all records from a binary file (also attached...

    Write a program in C++ to: 1. Read all records from a binary file (also attached to this email) to arrays; (the record structure: student number (20 bytes), grade (integer)) 2. Sort the list according to test scores; 3. Calculate the average test score for the class and print on the screen; 4. write sorted records to a new binary file. For example: The records in the original file: 1 89 2 95 3 76 The new file sorted by...

  • 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....

  • In C, write a program to read 5 student scores from keyboard the average of test...

    In C, write a program to read 5 student scores from keyboard the average of test score. Use for loop. Instead of entering the 5 scores each time you run the program, you can use i/o redirect. Create an input file inputfor.txt, then add 5 scores in it. Run the command like this: scorefor < inputfor.txt

  • C++ Write a program that reads students’ names followed by their test scores from the given...

    C++ Write a program that reads students’ names followed by their test scores from the given input file. The program should output to a file, output.txt, each student’s name followed by the test scores and the relevant grade. Student data should be stored in a struct variable of type StudentType, which has four components: studentFName and studentLName of type string, testScore of type int and grade of type char. Suppose that the class has 20 students. Use an array of...

  • Write you code in a class named HighScores, in file named HighScores.java. Write a program that...

    Write you code in a class named HighScores, in file named HighScores.java. Write a program that records high-score data for a fictitious game. The program will ask the user to enter five names, and five scores. It will store the data in memory, and print it back out sorted by score. The output from your program should look approximately like this: Enter the name for score #1: Suzy Enter the score for score #1: 600 Enter the name for score...

  • in c++ Program 1 Write a program that sorts a vector of names alphabetically using the...

    in c++ Program 1 Write a program that sorts a vector of names alphabetically using the selection sort and then searches the vector for a specific name using binary search. To do that, you need to write three functions I. void selSort (vector string &v: sorts the vector using selection sort 2. void display (const vector <string & v): displays the vector contents . int binSearch (const vector <ing& v, string key): searches the vector for a key returns the...

  • [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and...

    [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and methods must be used for this program. Process: •Read the number of students in a class. Make sure that the user enters 1 or more students. •Create an array with the number of students entered by the user. •Then, read the name and the test score for each student. •Calculate the best or highest score. •Then, Calculate letter grades based on the following criteria:...

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
ADVERTISEMENT