- 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”

30th Aug 2019, 2:38 PM
Bhavesh Kumar
12 ответов
+ 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
30th Aug 2019, 6:08 PM
Zeke Williams
Zeke Williams - avatar
+ 3
Do not expect people to do your homework for you.
30th Aug 2019, 5:15 PM
Zeke Williams
Zeke Williams - avatar
+ 2
if (person.shows(attempt)) { me.help(); }
30th Aug 2019, 4:56 PM
Shahil Ahmed
Shahil Ahmed - avatar
+ 1
for this you will need a few if—else statements and maybe a few loops.. preferably of the for kind. good luck
30th Aug 2019, 4:10 PM
Logomonic Learning
Logomonic Learning - avatar
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.
30th Aug 2019, 5:46 PM
Bhavesh Kumar
0
In C++ Course you have a good examples on how to read from txt files and how to write in them
30th Aug 2019, 10:07 PM
Feniks
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.
2nd Sep 2019, 5:01 PM
Bhavesh Kumar
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());
2nd Sep 2019, 6:09 PM
Zeke Williams
Zeke Williams - avatar
- 1
Can you please send me the pic of code?
30th Aug 2019, 2:53 PM
Bhavesh Kumar