- 5
How to write code for given problem?
Write a program that reads an existing file marks.txt. You have to search and print the marks of a student with a given enrolment number. The enrolment numbers is read as input from user. If an enrolment number is not in the file, just print, âEntry for this enrolment number does not existâ
12 Answers
+ 5
Bhavesh Kumar sincere apologies, if you are telling the truth. I don't mean to be rude. The Q&A receives a huge amount of questions that are homework related, so sorry for assuming the same about you.
You should still attempt it on your own and post the code here so that other mods don't assume the same. Good luck and Happy Coding
+ 3
Do not expect people to do your homework for you.
+ 2
if (person.shows(attempt))
{
me.help();
}
+ 1
for this you will need a few ifâelse statements and maybe a few loops.. preferably of the for kind. good luck
0
Hey đš, it is not Homework. This is just a practice problem which I want to learn. I know how to write in a file but don't know how to read so from this problem I can learn it.
So if you can help me then it ' s very good otherwise don't comment like this.
0
In C++ Course you have a good examples on how to read from txt files and how to write in them
0
int main()
{
int en1;
cin>>en1;
ifstream fin;
fin.open("myfile.txt"):
fin>>en1;
cout<<en1;
fin.close();
}
Here my logic is that I will enter enrolment no that exist in file and it will show marks corresponding to that. But how to print marks.
0
Bhavesh Kumar that is almost how you read a file. Here is writing and reading:
ofstream fout("myfile.txt");
int en1;
cin >> en1;
fout << en1;
fout.close();
Here is reading:
ifstream fin("myfile.txt");
string line;
std::getline(fin, line);
fin.close();
int en1 = atoi(line.c_str());
- 1
Can you please send me the pic of code?