using c++ Question 19 (14 points) (SLO: be able to call a function with arrays a
ID: 3721023 • Letter: U
Question
using c++
Question 19 (14 points) (SLO: be able to call a function with arrays as parameters) write the function main that does the following: 1. Define the arrays idlist to hold the IDs of 20 students (integer values) , and scorelist to hold their test scores (double precision values). Read the 20 students' IDs and their test scores from the standard input into the arrays idlist and scorelist respectively. Each input line will have an ID and a corresponding score. 2. 3. Read the ID of a student and look for his/her test score (by calling function searchld) in part c). 4. lfthe ID is found in the list (the value returned is not-1), its test score is printed; otherwise the message "ID not found" is printed.Explanation / Answer
Programplan:program has two arrays idlist and scorelist which stores the ids and score of the students.searchid is a function which takes student is as the argument and returns score if the student I'd is existed else shows the error message "ID not valid".
Program:
#include<iostream.h>
#include<conio.h>
int idlist[20];
float scorelist[20];
void searchid(int I'd);
void main()
{
int i,j;
clrscr();
cout<<"enter student details(ID and score)";
for(i=0;I<20;++i)cin>>idlist[i]>>scorelist[i];
cout<<"enter student ID";
cin>>k;
searchid(k);
getch();
}
void searchid( int id)
{
if(id==listed[i])
cout<<"student score is="<<scorelist[i]<<" ";
else cout<<"ID not valid";
}
Sample Output:
Enter student details:
1
253
2
356
3
425
4
652
5
463
6
953
7
955
8
653
10
582
11
652
12
652
13
852
14
862
15
785
16
842
17
842
18
785
19
452
20
452
Enter student ID:45
ID not valid.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.