i need a program that reads in data from standard input, putsthe data in an arra
ID: 3615328 • Letter: I
Question
i need a program that reads in data from standard input, putsthe data in an array of structs, and
then writes out the data in order of id number to standard output.The data in the input file looks
like this:
081 1986 71 143 029198 Baum Adam
015 1968 65 120 020509 Dente Al
094 1960 74 155 029836 Fresco Al
098 1986 51 073 037558 Romeo Alf
090 1987 55 086 024288 Katt Ali
096 1976 57 092 043721 Wellington Biff
where the fields are:
id, birthyear, height, weight, salary, lastname, firstname,
Each line of the input file corresponds to one person. Assume thatid’s are unique, but the id’s of
the input file are not in order and only a few of the potentialid’s are present. There may be any
number of lines of data. There is one or more space separating thefields of data. Use
redirection for the input file and the output file.
C:> reorder < inputFile.txt > outputFile.txt
The program is the write out the data in ascending order of idnumber. You do not have to sort
the data to do this. Merely read in the data line by line andinsert it into an array of structs that is
has one cell for each potential id number. Assume that id’sare in the range 001 to 099. Now
write out the cells of the array in ascending order and the datawill come out sorted. For the
above data,
the output should look something like:
id: 015 birth: 1968 height: 65 weight: 120 salary: 020509 name: AlDente
id: 081 birth: 1986 height: 71 weight: 143 salary: 029198 name:Adam Baum
id: 090 birth: 1987 height: 55 weight: 086 salary: 024288 name: AliKatt
id: 094 birth: 1960 height: 74 weight: 155 salary: 029836 name: AlFresco
Explanation / Answer
#include #include using namespace std; struct student{ int birth; int height; int weight; int salary; char lname[10]; char fname[10]; }clas[100]; int main() {int b; char ch; for(b=1;b0) {scanf("%d%d%d%d%s%s",&clas[b].birth,&clas[b].height,&clas[b].weight,&clas[b].salary,&clas[b].lname,&clas[b].fname); while (ch = getchar()!= ' ' ); } for(b=1;bRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.