Hey i made this program that uses classes and files, and im having trouble with the readfile constructor...
here is the code - #include <iostream.h>
-
#include <iomanip.h>
-
#include <fstream.h>
-
#include <string.h>
-
-
#define W setw
-
-
class student{
-
private:
-
char first[20], last[20];
-
int age;
-
double gpa;
-
public:
-
student();
-
void read();
-
void show();
-
void writefile();
-
int readfile(ifstream &);
-
double getGPA();
-
-
};
-
-
student::student() { gpa = 0;}
-
-
void student::read(){
-
cout << "Please enter the students first and last name, age, and gpa: ";
-
cin >> first >> last >> age >> gpa;
-
}
-
-
void student::show(){
-
cout << endl << W(10) << first << W(15) << last << W(3) << age << W(6) << gpa;
-
}
-
-
void student::writefile(){
-
ofstream OS("studentdata.txt", ios::app);
-
-
OS << W(10) << first << W(15) << last << W(3) << age << W(6) << gpa << endl;
-
OS.close();
-
}
-
-
int student::readfile(ifstream & IS){
-
IS << first << last << age << gpa;
-
return !IS.eof();
-
}
-
-
double student::getGPA() {return gpa;}
-
-
int main(void){
-
student s;
-
int i, n=0;
-
double sum =0;
-
char answer[1];
-
ifstream IS("studentdata.txt");
-
-
while(true){
-
s.read();
-
s.writefile();
-
n++;
-
cout << "Do you want to enter another student (y/n)? ";
-
cin >> answer;
-
-
if (answer[0] == 'n' || answer[0] == 'N'){
-
break;
-
}
-
}
-
-
for(i=0; i<n; i++){
-
s.readfile(IS);
-
s.show();
-
sum += s.getGPA();
-
}
-
-
cout << "\n The students average gpa is: " << sum/n;
-
cout << endl;
-
return 0;
-
}
this is the error i get: -
In method `int student::readfile(ifstream &)':
-
42: no match for `ifstream & << char[20]'
-
2 1402
nevermind i figured it out...
sorry guys i thought i had it but now im getting a segment fault and i cant figure out what the problem is. here is the code plz help!! -
#include <iostream.h>
-
#include <iomanip.h>
-
#include <fstream.h>
-
#include <string.h>
-
-
#define W setw
-
-
class student{
-
private:
-
char first[20], last[20];
-
int age;
-
double gpa;
-
public:
-
student();
-
void read();
-
void show();
-
void writefile();
-
int readfile(ifstream &);
-
double getGPA();
-
-
};
-
-
student::student() { gpa = 0;}
-
-
void student::read(){
-
cout << "Please enter the students first and last name, age, and gpa: ";
-
cin >> first >> last >> age >> gpa;
-
}
-
-
void student::show(){
-
cout << endl << W(10) << first << W(15) << last << W(3) << age << W(6) << gpa;
-
}
-
-
void student::writefile(){
-
ofstream OS("studentdata.txt", ios::app);
-
-
OS << W(10) << first << W(15) << last << W(3) << age << W(6) << gpa << endl;
-
OS.close();
-
}
-
-
int student::readfile(ifstream & IS){
-
IS >> first >> last >> age >> gpa;
-
return !IS.eof();
-
}
-
-
double student::getGPA() {return gpa;}
-
-
int main(void){
-
student s, r[20];
-
int i, n=0;
-
double sum =0;
-
char answer[1];
-
ifstream IS("studentdata.txt");
-
-
while(true){
-
s.read();
-
s.writefile();
-
cout << "Do you want to enter another student (y/n)? ";
-
cin >> answer;
-
-
if (answer[0] == 'n' || answer[0] == 'N'){
-
break;
-
}
-
}
-
-
while(r[i].readfile(IS))
-
n++;
-
for(i=0; i<n; i++){
-
r[i].readfile(IS);
-
r[i].show();
-
sum += r[i].getGPA();
-
}
-
-
cout << "\n The students average gpa is: " << sum/n;
-
cout << endl;
-
return 0;
-
}
Thanks
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: PHPkemon |
last post by:
Hi there,
A few weeks ago I made a post and got an answer which seemed very logical.
Here's part of the post:
PHPkemon wrote:
> I think I've figured out how to do the main things like storing products
in
|
by: wukexin |
last post by:
Help me, good men. I find mang books that introduce bit "mang header
files",they talk too bit,in fact it is my too fool, I don't learn it, I have
do a test program, but I have no correct doing result in any way. Who can
help me, I thank you very very much.
list.cpp(main program)
//--------------------------------------------------------------------------
-
#pragma hdrstop
#pragma argsused
|
by: Bec |
last post by:
I'm in desperate need of your help..
I need to build an access database and have NO idea how to do this..
Not even where to start..
It IS for school, and am not asking anyone to do my homework for me.. I
am merely asking for help, perhaps pointers as to where to begin..
I've never used access before.. I'm rather cluey when it comes to
|
by: tyler_durden |
last post by:
thanks a lot for all your help..I'm really appreciated...
with all the help I've been getting in forums I've been able to continue
my program and it's almost done, but I'm having a big problem that I
believe if it's solved, the remaining stuff is easy...
my full program until now is here:
http://www.geocities.com/tom4_h4wk/progmail.zip
the problem is the segmentation fault when main trys to run
leficheiro.c.... the *.c2 files are the...
|
by: Erik |
last post by:
Hi Everyone,
I'm having real problems compiling some source for eVC4++. The errors
I am getting are below:
It all seems to be centred around winsock. If I move the afsock.h
reference to before my other includes then I get lots of errors like
C2011: 'fd_set' : 'struct' type redefinition
warning C4005: 'FD_CLR' : macro redefinition
which I understand are due to the fact that windows.h is being
included in another header file as well as...
| |
by: Bsnpr8 |
last post by:
I need help guys, i have to many stuff to do, because i am in my last 2 weeks of the university, my last assignment is to do a spell checker in C++, i have an idea but nothing is coming out. I really need help, could someone do, anything to help me i don't have much time, here are the instructions:
Instructions:
In this project, you are asked to develop your own spell-checker utility. We make suggestions to help get you started. You should...
|
by: HelpME |
last post by:
I wrote a program in Vb.Net that was running fine. However I am
unable to install it on a couple of machines. When i run it I get a
windows error message that says
My Project.exe has encountered a problem and needs to close. We are
sorry for the inconvience.
If you were in the middle of something, the information you were
working on might be lost
|
by: ligong.yang |
last post by:
Hi all,
I got tortured by a very weird problem when I was using k. wilder's
random generator class in my program. PS: wilder's generator class can
be found at http://oldmill.uchicago.edu/~wilder/Code/random/.
Firstly, I got the notorious "fatal error C1010: unexpected end of file
while looking for precompiled header directive" error when I tried to
compile 'randtest.c' provided by wilder.
|
by: ligong.yang |
last post by:
Hi all,
I got tortured by a very weird problem when I was using k. wilder's
random generator class in my program. PS: wilder's generator class can
be found at http://oldmill.uchicago.edu/~wilder/Code/random/.
Firstly, I got the notorious "fatal error C1010: unexpected end of file
while looking for precompiled header directive" error when I tried to
compile 'randtest.c' provided by wilder.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |