anybody help me remove the errors from the following C++ program ??? Please re post the code after the errors have been removed. People please help me.. i dont know anything a bout C++ programming.. this is my home work.. i dont know how to remove errors.. please help....
#include<fstream.h>
#include<conio.h>
struct emp
{
int emp_no;
char name[50];
long salary;
char dept[30];
}arr[50]; /*Data types of 4 records created*/
void main()
{
int n,i=0;
ofstream myfile;
myfile.open ("example.bin", ios::out | ios::app | ios::binary); /*Data file created*/
cout<<"How many records u want to enter - ";
cin>>n;
while(i!=n)
{
cout<<"\nEneter emp no for record "<<i+1<<":- ";
cin>>arr[i].emp_no;
cout<<"\nEnter name--- ";
cin>>arr[i].name;
cout<<"\nEnter salary:--- ";
cin>>arr[i].salary;
cout<<"\nenter Department Name :--- ";
cin>>arr[i].dept;
//if (myfile.is_open())
{
myfile.write((char*) &arr[i],sizeof(arr[i])); /*Adding records to Data file*/
}
i++;
}
myfile.close();
ifstream mfile;
mfile.open ("example.bin", ios::in | ios::app | ios::binary);
cout<<"\nWhich record u want to modify-- ";
cin>>i;i--;
mfile.seekg(i,ios::beg);
cout<<"\nEneter emp no for record "<<i+1<<" :- ";
cin>>arr[i].emp_no;
cout<<"\nEnter name--- ";
cin>>arr[i].name;
cout<<"\nEnter salary:--- ";
cin>>arr[i].salary;
cout<<"\nenter Department Name :--- ";
cin>>arr[i].dept;
mfile.read((char*) &arr[i],sizeof(arr[i])); /*Modifying the file*/
mfile.close();
getch();
}
Your homework is to remove errors, or to write the program? If your homework is to correct it, nobody will help you. Otherwise, could you elaborate, maybe tell us what lines have the errors?
I see two errors in the very beginning of the program. The first is that you should name standard C++ header files without extension that is instead of <fstream.h> should be <fstream> (if you are using a modern compiler). Also I see that you should include header <iostream>. And in C++ main is declared as int main()
Also, you don't have a usingnamespace std; anywhere in your program. Your C++ compiler won't know where to look for cout, cin, and ofstreams without that and without being prefixed by std::, like so:
>> i dont know anything about c++... please help me or i will lose 15 marks from my final assessment !! please i m a noob
the mark you get for your assessment should reflect your understanding of the material you're supposed to have learned. If you're on a course and haven't learned anything, then why should you have any marks for it?
I agree with Bench 82. And you still haven't told us which lines have errors. Do you even have a compiler, or are you just trying to squeeze through the class so you can get a well-paying programming job which you'll only keep for two months until they realize that you don't know it? Not trying to be offensive, but if you try to work with us, you're more likely to get help.
#include<fstream.h>
#include<conio.h>
struct emp
{
int emp_no;
char name[50];
long salary;
char dept[30];
}arr[50]; /*Data types of 4 records created*/
void main()
{
int n,i=0;
ofstream myfile;
myfile.open ("example.bin", ios::out | ios::app | ios::binary); /*Data file created*/
cout<<"How many records u want to enter - ";
cin>>n;
while(i!=n)
{
cout<<"\nEneter emp no for record "<<i+1<<":- ";
cin>>arr[i].emp_no;
cout<<"\nEnter name--- ";
cin>>arr[i].name;
cout<<"\nEnter salary:--- ";
cin>>arr[i].salary;
cout<<"\nenter Department Name :--- ";
cin>>arr[i].dept;
//if (myfile.is_open())
{
myfile.write((char*) &arr[i],sizeof(arr[i])); /*Adding records to Data file*/
}
i++;
}
myfile.close();
ifstream mfile;
mfile.open ("example.bin", ios::in | ios::app | ios::binary);
cout<<"\nWhich record u want to modify-- ";
cin>>i;i--;
mfile.seekg(i,ios::beg);
cout<<"\nEneter emp no for record "<<i+1<<" :- ";
cin>>arr[i].emp_no;
cout<<"\nEnter name--- ";
cin>>arr[i].name;
cout<<"\nEnter salary:--- ";
cin>>arr[i].salary;
cout<<"\nenter Department Name :--- ";
cin>>arr[i].dept;
mfile.read((char*) &arr[i],sizeof(arr[i])); /*Modifying the file*/
mfile.close();
getch();
}
What course are you even on?
- If it isn't a programming one, why have you got this as homework?
- If it is a programming one, how do you not know anything at all about C++?
Are you exaggerating how much you don't know about C++, ie do you know the basics like cout << "Hey";, if statements etc?
You kind of keep just asking for help in the most vague way. "I don't know anything, just help me, fix these errors, come on help me, I'm gonna fail". I don't really think anyone has any idea about what you want doing.