Answer to Question #210218 in C++ for heloo

Question #210218

Complete the void function below to read a list of students’ record in text1.txt (name, id, phone number), then input a student name (s) and search if it is exist in the list of names. Print out the record of that student.

 void student(string s ,ifstream &in)

 {

        // read each line and compare the name s

  }

 

int main()

 {

    string s; cin>>s;  // input string

    ifstream in;              

    in.open("Text1.txt");

    student(s, in);  

    system("pause");

    return 0;

 }


1
Expert's answer
2021-06-24T07:34:49-0400
#include<iostream>
#include<ifstream>
using namespace std;
void student(string s, ifstream &in)
{
  string name;
  string phone_number;
  long long int id;
  in >> name >> id >> phone_number;
  if (s == name) {
    cout << name << ' ' << id << ' ' << phone_number << endl;
  }
}

int main()
{
    string s; cin>>s;  // input string
    ifstream in;              
    in.open("Text1.txt");
    student(s, in);  
    system("pause");
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS