actually i have a lot of problems with code down. i actually i made this code to let create a file for several student, i tried by my name but unfortunately i got alot of errors i don't know how can i debug them. if anyone of you know how to complete the program by making the user to enter so many student and their marks and let the user to make some modification or edit his or her names, i want at least 100 student to enter their names, ids,marks, and display the name, the id,the avarage marks for each student in files,this is the code,
i wish i can get a complete program. please help me and thank you, it is really important, i am really thankful for all of you,have a great time guys -
#include<iostream>
-
#include<fstream>
-
using namespace std;
-
const int SIZE=100;
-
class Info{
-
private:
-
string id;
-
double mark;
-
-
-
public:
-
Info();
-
void display();
-
void getData();
-
void setMark(double); // change the value.
-
double getMark(); // assest the value
-
string getName();
-
-
};
-
-
Info:: Info(){
-
id=" ";
-
mark=0;
-
}
-
void Info:: getData(){
-
cout<<" please enter the student id:"<<endl;
-
getline(cin,id);
-
cout<<" please enter the student mark:"<<endl;
-
cin>> mark;
-
std:: cin.ignore();
-
}
-
void Info:: display(){
-
cout<<id<< "\t"<< mark << endl;
-
-
}
-
void Info::setMark(double m){
-
mark=m;
-
}
-
double Info::getMark(){
-
return mark;
-
}
-
void save(Info s[], int SIZE){
-
ofstream myfile;
-
myfile.open("mark.sami");
-
for( int i=0; i<SIZE; i++)
-
myfile<< s[i].getName <<"\t"<<s[i].mark<<endl<<endl;;
-
myfile.close();
-
}
-
void load(){
-
string line;
-
ifstream myfile("mark.sami");
-
if(myfile.is_open())
-
{
-
while(! myfile.eof())
-
{
-
getline(myfile,line);
-
cout<<line<< endl;
-
}
-
myfile.close();
-
}
-
else cout<< " Unable to open file"<<endl;
-
}
-
-
int main()
-
{
-
Info std[SIZE];
-
for(int i=0; i<SIZE; i++)
-
std[i].getData();
-
cout<<" \nName\tmark"<<endl;
-
cout<<"=========================="<<endl;
-
// load();
-
for(int i=0; i<SIZE; i++)
-
std[i].display();
-
save(std,SIZE);
-
-
return 0;
-
}
15 1842
What are the errors you are getting? Can you copy and paste them here as well?
if u don't mind, u can copy and paste the code and compile it, actually i didn't know how to create a file for each students, i think the errors is ,"Double Marks is private" i really don't know what does it mean, i tried to change to other types but still the same errors, still so weak in designing a programs because i have not learn classes in deep
if u don't mind, u can copy and paste the code and compile it, actually i didn't know how to create a file for each students, i think the errors is ,"Double Marks is private" i really don't know what does it mean, i tried to change to other types but still the same errors, still so weak in designing a programs because i have not learn classes in deep
I can, but I would like you to look at the errors - my goal here is not just to fix your program, but help you be able to diagnose a similar issue in the future, hopefully make you a better and more independent programmer (and then you can come back and maybe even help me!).
there're some errors just because you forgot to include a header file <string>
for example, when you compile your code, you'll get a error hint that getline() function does not take one argument, but you do offer it two arguments, with a ifstream myfile and a string line.
why does compiler consider you just give it only one argument?
It's because that you declare the variable "line" by using "string line" but you don't tell compiler what the string is by including <string>.
By the by, I use VS2005, maybe some other compilers can recognise it without <string> header file... I don't make a test.
Moreover, please pay attention to this line
"myfile<< s[i].getName <<"\t"<<s[i].mark<<endl<<endl;;"
you wanna get the s[i]'s name via a function named getName, so when you call that function, you should write it as "s[i].getName()". Do not forget the parentheses, without them the compiler would take getName a variable of s[i], other than a member function.
Another problem is, you wanna get s[i]'s mark via a directly visit, however, the member mark in your Info class is defined private, which means you cannot visit it directly or it's invisable to you, the only way you get it is using the interface you defined in your Info class, "getMark()".
I can, but I would like you to look at the errors - my goal here is not just to fix your program, but help you be able to diagnose a similar issue in the future, hopefully make you a better and more independent programmer (and then you can come back and maybe even help me!).
thank you Sicarie. actually i am a new programmer and i have learned classes in deep, i just read from book and that question i posted is my exercise, i tried it out and did the best i could but i got the bugs actually i don't how to use " double mark") it is private, i don't know how to deal with it. hopefully u can help me out, thank you so much.
thank thank thank you so much. it is really working, thank you so much, but one more thing if u don't mind, how can i get the avarage months for each students and make a file for each a students, your help is highly appreciated, thank you so much, but in the program it can not create a file, how i do that?
thank you so much, but u know i still have a problem of creating a file for each student and display the average marks for each one in file .i wish u help out to figure this problem.
there're some errors just because you forgot to include a header file <string>
for example, when you compile your code, you'll get a error hint that getline() function does not take one argument, but you do offer it two arguments, with a ifstream myfile and a string line.
why does compiler consider you just give it only one argument?
It's because that you declare the variable "line" by using "string line" but you don't tell compiler what the string is by including <string>.
By the by, I use VS2005, maybe some other compilers can recognise it without <string> header file... I don't make a test.
Moreover, please pay attention to this line
"myfile<< s[i].getName <<"\t"<<s[i].mark<<endl<<endl;;"
you wanna get the s[i]'s name via a function named getName, so when you call that function, you should write it as "s[i].getName()". Do not forget the parentheses, without them the compiler would take getName a variable of s[i], other than a member function.
Another problem is, you wanna get s[i]'s mark via a directly visit, however, the member mark in your Info class is defined private, which means you cannot visit it directly or it's invisable to you, the only way you get it is using the interface you defined in your Info class, "getMark()".
thank you so much, but u know i still have a problem of creating a file for each student and display the average marks for each one in file .i wish u help out to figure this problem.
ur.. I dont understand your requirement very much:(
will u please show me a more specific example showing your requirement?
regards..
thank you so much, but u know i still have a problem of creating a file for each student and display the average marks for each one in file .i wish u help out to figure this problem.
Do you have a list of the students beforehand? Otherwise, you'll have to create these files dynamically, which can get interesting.
Off the top of my head, I'd recommend creating an array of strings, and then filling that with the names, then when you create the outfiles for the individual students, you can use those strings as the names of the files. I'd also recommend using strcpy() or another of the functions here to tack on the absolute file location, otherwise you'll have to find where the file was created. That's easy enough with the search function, but it's easier to just put them in a directory that's easy to access.
ur.. I dont understand your requirement very much:(
will u please show me a more specific example showing your requirement?
regards..
thank you, actually my requirement is to create a file for 100 students and display in the file the avarage marks for each student and his name,and make the the user to edit some of his informations
thank you, actually my requirement is to create a file for 100 students and display in the file the avarage marks for each student and his name,and make the the user to edit some of his informations
So just one file, correct? You can use an fstream (google c++ file io or c file io), and that will create the file.
So just one file, correct? You can use an fstream (google c++ file io or c file io), and that will create the file.
[ i need more than one file. i have 100 students, so i need to create a file for each one of them which can show their names,avarages marks,] thank you so much
Regards
Alkindi
[ i need more than one file. i have 100 students, so i need to create a file for each one of them which can show their names,avarages marks,] thank you so much
Regards
Alkindi
Then yeah, my post #10 would be the way I would approach the problem.
i wish u can get my wants or requirement, actually here i can not create a file and cin the information for each students, i want the size to 100, but unfortunately i can not use the for loop
#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>
using namespace std;
const int size=10;
int main()
{
ifstream inFile;
ofstream outFile;
int quiz1, quiz2, quiz3, quiz4, quiz5;
double average;
char studentId;
inFile.open("a:\\quiz.txt");
outFile.open("a:\\quizavg.out");
// for(int i=0 ; i< size; i++)
cout<<" the students information"<<endl;
inFile>>studentId;
outFile<<" student ID: "<< studentId<< endl;
inFile>> quiz1>>quiz2>> quiz3>> quiz4>> quiz5;
outFile<<" Quize scores:"<< setw(4)<< quiz1
<< setw(4)<< quiz2<< setw(4)<< quiz3<< setw(4)<< quiz4
<<setw(4)<<quiz5<< endl;
average= static_cast<double>(quiz1+quiz2+quiz3+quiz4+quiz5)/5.0;
outFile<< " Average test score:"<< setw(6)<< average<< endl;
inFile.close();
outFile.close();
system("pause");
return 0;
}
i wish u can get my wants or requirement, actually here i can not create a file and cin the information for each students, i want the size to 100, but unfortunately i can not use the for loop
#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>
using namespace std;
const int size=10;
int main()
{
ifstream inFile;
ofstream outFile;
int quiz1, quiz2, quiz3, quiz4, quiz5;
double average;
char studentId;
inFile.open("a:\\quiz.txt");
outFile.open("a:\\quizavg.out");
// for(int i=0 ; i< size; i++)
cout<<" the students information"<<endl;
inFile>>studentId;
outFile<<" student ID: "<< studentId<< endl;
inFile>> quiz1>>quiz2>> quiz3>> quiz4>> quiz5;
outFile<<" Quize scores:"<< setw(4)<< quiz1
<< setw(4)<< quiz2<< setw(4)<< quiz3<< setw(4)<< quiz4
<<setw(4)<<quiz5<< endl;
average= static_cast<double>(quiz1+quiz2+quiz3+quiz4+quiz5)/5.0;
outFile<< " Average test score:"<< setw(6)<< average<< endl;
inFile.close();
outFile.close();
system("pause");
return 0;
}
The A:\ drive is usually recognized as 'floppy disk,' are you trying to write to a floppy, or your hard drive? It's possible that the letter was assigned to a local drive, but I'd check that out. (C is usually the hard disk)
If you can't use a for loop, why not use one of the other loops to mimick a for loop? Such as while counter < 100 do stuff, and increment counter. Or if counter < 100, dostuff, increment counter.
At first glance, your files look like they're declared properly (unless there's no floppy in there...).
Sign in to post your reply or Sign up for a free account.
Similar topics
by: MLH |
last post by:
I am having failures processing the following command and I wonder
if you can tell me what I must do in order to have success. When I try
to run source mysql_dump.sql.txt ==> it is a problem...
|
by: longtim |
last post by:
I have been having endless difficulty creating reports/queries that
set any relevent parameters from controls in forms.
I am creating an application under access 2003 but will target access...
|
by: Simon Edwards |
last post by:
Something thats been bugging me for a while...
how do you create a namespace that has many children (namespaces)
I.e system.io.blah.blah
Iv'e done it by creating a class which contains...
|
by: David Thielen |
last post by:
Hi;
My ASP.NET app (C# calling J# under .net 2.0) creates a png file in a
subdirectory to display as part of the created page. However, the bitmap will
not display due to a security violation.
...
|
by: Bugs |
last post by:
Hi,
I wonder if anyone can help me out.
I'm building a vb.net application that has a form with a panel that
contains several other sub forms (as a collection of controls). What
I'm wanting to...
|
by: Lee Harr |
last post by:
I understand how to create a property like this:
class RC(object):
def _set_pwm(self, v):
self._pwm01 = v % 256
def _get_pwm(self):
return self._pwm01
pwm01 = property(_get_pwm, _set_pwm)
| |
by: Rico |
last post by:
Hello,
I'm trying to create a simple back up in the SQL Maintenance Plan that will
make a single back up copy of all database every night at 10 pm. I'd like
the previous nights file to be...
|
by: GesterX |
last post by:
First of all I'm new to this site but it certainly looks like a place that i will be visiting more often!
Onto my problem.
I am creating a Hotel Bussiness project in java using BlueJ
The...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |