Write the pseudocode to do the following: a. Read a data file containing 30 stud
ID: 3654673 • Letter: W
Question
Write the pseudocode to do the following: a. Read a data file containing 30 student names, ID number, and gender into an array. b. Print the contents of each record using the array. c. Count the number of male and female students by using the array, and print the counts. Hints: 1. The file will contain 30 students. So 30 will be the size of your arrays. 2. You will use 3 parallel arrays. One for the names, one for the ID numbers, and one for the genders. 3. You will use a loop to read the data from the file and output the data. Since you are inputting this data from a file there will not be any prompts. For those of you more familiar with programming, do not worry about opening the data file. 4. You will use an if statement to determine if the gender is male or female. This can be done in the same loop as you input the data.Explanation / Answer
//declare variables string name[30]; int ID[30]; char gender[30]; int male =0; //open file ifstream infile("Nameof File"); //check to see if file opened failed if(!infile.is_open()){ output error message } else{//opened successfully //so process file for(int i=0;i>name[i]>>ID[i]>>gender[i]; //count gender if(gender[i]=='m'||gender[i]=='M') male++; }//end for loop //output data coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.