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

PROBLEM: You are given a file named \"course_roster.csv\" (on Angel) containing

ID: 3539529 • Letter: P

Question

PROBLEM:

You are given a file named "course_roster.csv" (on Angel) 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, 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 it to the user. For extra credit(5 points), have your program ask the user if they would like to search for another student and repeat the process until they answer in the negative.

HINTS:

1. Use c-strings to store texts, you can use as many as you feel necessary

2. 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!).

3. You need to format the string of the input name so that it will match the format of names in the file.

4. Another function that might be useful is getline() since the >> operators read only up to any whitespace.


NOTE:- I have pasted the file (course_roster) at the location where my project is saved !!!!!


Explanation / Answer

#include <fstream>

#include <iostream>

#include <string.h>

#include <stdio.h>

using namespace std;


int main()

{

char name[50];

char fName[25], lName[25];

int myChoice = 1;

while(myChoice!=0)

{

cout<<"Enter the student name : ";

cin.getline(name,50);

ifstream in;

in.open("course_roaster.csv");

char tempName[100];

int rank = 0;

int count = 0;

while(!in.eof())

{

in >> lName >> fName;

strcpy(tempName,fName);

strcat(tempName, " ");

strcat(tempName, lName);

count++;

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

{

rank = count;

break;

}

}

if(rank !=0)

{

cout<<name <<" has rank "<<rank<<endl;

}

else

{

cout<<name <<" does not exists in file."<<endl;

}


cout<<"Search again?"<<endl;

cout<<"Enter 1 for yes , 0 for no :";

cin>>myChoice;

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