Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In this problem,You are given a file containing an ordered list of all students

ID: 3539622 • Letter: I

Question

In this problem,You are given a file containing an ordered list

of all students in the class.Each name is on its own line in the file and is listed in the

following format: LAST to FIRST

Your program should prompt the user and accept the first name and then the last

name of a student (assume that the user enters both names in all capitals). Using

this input, you must determine the rank of the student according to the list in the

file. If the name is not found, you should report itto the user.


Hints:

-Use c-strings to store text. You can use as many as you feel necessary.

- You will probably want to use c-string functions that were introduced in

class, e.g., strcpy(), strcmp(), strcat(). You can find documentation and

examples of these in the book and online (do not copy them, just reference

them!).

-You need to format the string of the input name so that it will match the

format of names in the file.

- Another function that might be useful is getline() since the >> operators read

only up to any whitespace.

- Use good file input/output practice - make sure the file opens correctly and

be sure to close it.


Please help me out as this is urgent and need help!

Thank you so much

Explanation / Answer

#include <iostream>

#include <stdio.h>

#include <string.h>

#include <fstream>

using namespace std;


int main()

{


char name[100];

int choice = 1;

while(choice)

{

cout<<"Enter the name : ";

cin.getline(name, 100);

char firstName[50], lastName[50];

bool found = false;

int rank = 0;

ifstream inFile("course_roaster.csv");

while(!inFile.eof())

{

inFile >> lastName;

inFile >> firstName;

char nameFromFile[100];

strcpy(nameFromFile,firstName);

strcat(nameFromFile," ");

strcat(nameFromFile,lastName);

rank++;

if(strcmp(name, nameFromFile)==0)

{

found = true;

break;

}

}

if(found==1)

cout << "Rank of "<<name <<" is "<<rank<<endl<<endl;

else

cout<<name <<" not found in file."<<endl<<endl;

inFile.close();



cout<<"Search another student ? "<<endl;

cout<<"Enter any number continue and 0 to exit: ";

cin>>choice;

getchar();

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote