Answer to Question #214035 in C++ for Hemambar

Question #214035

Write a program to store Student objects in a file, search for a student and display his details.

The program also should display the number of the object from the beginning and the end of the

file.


1
Expert's answer
2021-07-17T01:30:42-0400
using namespace std;
#include <omp.h>
#include <stdio.h>

#define NO_OF_STUDENTS	5
class Student
{
	public:
		string Name;
		int ID;
		setStudent(string s, int n)
		{
			Name=s;
			ID = n;
		}
};


main(void)
{
	class Student S[NO_OF_STUDENTS];
	string Name = "H:\\Student.txt";
	string STNames[NO_OF_STUDENTS];
	int IDs[NO_OF_STUDENTS];
	int n,SearchID,Flag=0;
	char x;
	fstream outfile,infile; 
	outfile.open(Name.c_str());
	
	S[0].setStudent("AAA",111);	
	S[1].setStudent("BBB",222);	
	S[2].setStudent("CCC",333);	
	S[3].setStudent("DDD",444);	
	S[4].setStudent("EEE",555);	
	
	for(n=0;n<NO_OF_STUDENTS;n++)
	{
		outfile<<S[n].Name<<"\t"<<S[n].ID<<endl;
	}
	outfile.close();
	
	cout<<"\nEnter the Student ID to search: "; cin>>SearchID;
	for(n=0;n<NO_OF_STUDENTS;n++)
	{
		if(S[n].ID == SearchID) 
		{
			Flag=1;
			cout<<"\nStudent Found with details";
			cout<<"\nName: "<<S[n].Name<<"\tID = "<<S[n].ID;
		}
	}
	if(Flag==0) cout<<"\nThe student with ID = "<<SearchID<<" not found";
	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