469,625 Members | 1,169 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,625 developers. It's quick & easy.

Help~! I don't know what's wrong with this program.

#include<iostream>
#include<iomanip>
#include<cstring>
#include<fstream>
using namespace std;

class snowfall
{
private:
int ft;

float in;
float totalsfin;

char date[6];

static int validcount;
static int invalidcount;

public:
void readdata(ifstream& infile)
{
infile>> ft >> in >> date;
}

void writedata(ofstream& outfile)
{
outfile<< ft << in << date;
}

void updatevalidcount()
{
validcount++;
}

void updateinvalidcount()
{
invalidcount++;
}

void calctotalsf()
{
totalsfin += float(ft)*12 + in;
}

int getft()
{return ft;}

float getin()
{return in;}

char* getdate()
{return date;}

int getvalidcount()
{return validcount;}

int getinvalidcount()
{return invalidcount;}

int operator == (char[]);
char datavalid();
void writetotalsf(ofstream& outfile);
};

int snowfall::operator == (char sf[])
{
return (strcmp(date, sf) == 0) ? 1 : 0;
}
char snowfall::datavalid()
{
char valid;

if ((ft >= 0) && (in >= 0.0f))
valid = 'T';
else
valid = 'F';
return valid;
}
void snowfall::writetotalsf(ofstream& outfile)
{
int totalsfft = 0;

if (totalsfin >= 12.0f)
while (totalsfin <= 11.0f)
{
totalsfft++;
totalsfin -= 12.0f;
}

outfile<< "/nThe total amount of snowfalls: " << totalsfft
<< " feet " << totalsfin << " inches.\n";
}
void main()
{
snowfall sf[10];
snowfall validsf[10];
snowfall invalidsf[10];

void writetitle(ofstream&);
void writeheadings(ofstream&);
void sortsf(snowfall);
void writevalidsf(snowfall, ofstream&);
void writeinvalidsf(snowfall, ofstream&);
ifstream infile;
ofstream outfile;

infile.open("c:\\downloads\\input.txt");
outfile.open("c:\\downloads\\output.txt");

if (infile && outfile)
{
int j = 0;
int k = 0;

writetitle(outfile);

for (int i = 0; i <= 10; i++)
{
sf[i].readdata(infile);

if (sf[i].getdate() == "00/00")
i = 10;
else
{
if (sf[i].datavalid() == 'T')
{
validsf[j] = sf[i];
sf[i].updatevalidcount();
sf[i].calctotalsf();
j++;
}
else
{
invalidsf[k] = sf[i];
sf[i].updateinvalidcount();
k++;
}
}
}

sortsf();
writeheadings(outfile);
writevalidsf(outfile);
writeinvalidsf(outfile);
validsf[i].writetotalsf(outfile);
}
else
{
if (!infile)
cout<< "Unable to open file input.txt.\n";
if (!outfile)
cout<< "Unable to open file output.txt.\n";
}
}

void writetitle(ofstream& outfile)
{
outfile<< "Title\n\n";
}
void writeheading(ofstream& outfile)
{
outfile<< "Headings\n\n";
}
void sortsf(snowfall validsf[])
{
snowfall temp;

for (int i; i = validsf[i].getvalidcount(); i++)
for (int j; j = i + 1; j++)
if ((float(validsf[i].getft()) * 12 + validsf[i].getin()) >
(float(validsf[j].getft()) * 12 + validsf[j].getin()))
{
temp = validsf[i];
validsf[i] = validsf[j];
validsf[j] = temp;
}
}
void writevalidsf(snowfall validsf[], ofstream& outfile)
{
for (int i=0; i = validsf[i].getvalidcount(); i++)
validsf[i].writedata(outfile);
}
void writeinvalidsf(snowfall invalidsf[], ofstream& outfile)
{
if (invalidsf[0].getinvalidcount() != 0)
for (int i = 0; i = invalidsf[i].getinvalidcount(); i++)
outfile<< "Invalid amount of snowfall for the date, "
<< invalidsf[i].getdate() << endl;
}

Jul 22 '05 #1
5 2527

What kind of help do you need? You haven't said what problems you are
having. Does it compile? Does it crash? Does it incorrectly print out the
latest football stats (like putting the 49ers in 1st place)??? :-)

It's a fair amount of work for someone to simply look at a program and guess
what it is supposed to do, and whether it will actually do that. We really
need more information from you as to what exactly is going wrong before we
can tell you why that might be the case.

-Howard
Jul 22 '05 #2
This is the error messages I'm getting.

Program4.cpp
C:\Program Files\Microsoft Visual
Studio\MyProjects\Program4\Program4.cpp(146) : error C2660: 'sortsf' :
function does not take 0 parameters
C:\Program Files\Microsoft Visual
Studio\MyProjects\Program4\Program4.cpp(148) : error C2660:
'writevalidsf' : function does not take 1 parameters
C:\Program Files\Microsoft Visual
Studio\MyProjects\Program4\Program4.cpp(149) : error C2660:
'writeinvalidsf' : function does not take 1 parameters
Error executing cl.exe.

Program4.exe - 3 error(s), 0 warning(s)

when I click on the error messge, it brings me to this line on the
source code.

sortsf(validsf);
writeheadings(outfile);
writevalidsf(validsf, outfile);
writeinvalidsf(invalidsf, outfile);
validsf[i].writetotalsf(outfile);

Jul 22 '05 #3
ti*******@hotmail.com wrote in news:1102958364.558876.130680
@z14g2000cwz.googlegroups.com:
This is the error messages I'm getting.

Program4.cpp
C:\Program Files\Microsoft Visual
Studio\MyProjects\Program4\Program4.cpp(146) : error C2660: 'sortsf' :
function does not take 0 parameters
C:\Program Files\Microsoft Visual
Studio\MyProjects\Program4\Program4.cpp(148) : error C2660:
'writevalidsf' : function does not take 1 parameters
C:\Program Files\Microsoft Visual
Studio\MyProjects\Program4\Program4.cpp(149) : error C2660:
'writeinvalidsf' : function does not take 1 parameters
Error executing cl.exe.

Program4.exe - 3 error(s), 0 warning(s)

when I click on the error messge, it brings me to this line on the
source code.

sortsf(validsf);
writeheadings(outfile);
writevalidsf(validsf, outfile);
writeinvalidsf(invalidsf, outfile);
validsf[i].writetotalsf(outfile);


Oh my. Please tell me that you at least indent your code? Also, you may
wish to take up the practice of writing small pieces of code _first_, see
if they compile, then add more (ie: incremental development). Start
with:

int main()
{
}

then compile.

Then add the basic frame of your snowfall class (ie: an empty class named
snowfall), and compile. Repeat in small steps until you get a complete
program. As you gain experience, these small steps may get larger.
Indentation of your code is there for your comprehension of your own code
(and other people trying to comprehend your code....).

A couple things to note:

1) void main() is non-standard. use "int main()".
2) If you write your extra functions before your main function, you have
no need to forward-declare them. Looking at sortsf in particular, you
declare it in main to take an object of type snowfall by value, you later
call it without passing a parameter at all, and finally define it taking
an array of snowfall. Make up your mind.....
3) With a quick glance it looks like you're doing something similar with
the other functions too.
Jul 22 '05 #4

<ti*******@hotmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
This is the error messages I'm getting.

Program4.cpp
C:\Program Files\Microsoft Visual
Studio\MyProjects\Program4\Program4.cpp(146) : error C2660: 'sortsf' :
function does not take 0 parameters
C:\Program Files\Microsoft Visual
Studio\MyProjects\Program4\Program4.cpp(148) : error C2660:
'writevalidsf' : function does not take 1 parameters
C:\Program Files\Microsoft Visual
Studio\MyProjects\Program4\Program4.cpp(149) : error C2660:
'writeinvalidsf' : function does not take 1 parameters
Error executing cl.exe.

Program4.exe - 3 error(s), 0 warning(s)
These error messages are imo very clear: You've passed the
wrong number of arguments when calling these functions.
Also, your prototypes are wrong.

The prototypes from your originial post:

void sortsf(snowfall); /* requires one argument */
void writevalidsf(snowfall, ofstream&); /* requires two arguments */
void writeinvalidsf(snowfall, ofstream&); /* requires two arguments */

You also have other problems. The actual function definitions:
void sortsf(snowfall validsf[])
{
/* etc */
}

The prototype above does not match this function's signature.
The number of parameters matches, but the type is wrong.
'snowfall' and 'snowfall[]' are not the same type.

void writevalidsf(snowfall validsf[], ofstream& outfile)
{
/* etc */
}

The prototype above does not match this function's signature.
The number of parameters matches, but the type of the first one
is wrong. 'snowfall' and 'snowfall[]' are not the same type.

void writeinvalidsf(snowfall invalidsf[], ofstream& outfile)
{
/* etc */
}

The prototype above does not match this function's signature.
The number of parameters matches, but the type of the first one
is wrong. 'snowfall' and 'snowfall[]' are not the same type.

Your calls to these functions in 'main()':

sortsf(); /* no argument given */
writevalidsf(outfile); /* only one argument given */
writeinvalidsf(outfile); /* only one argument given */


when I click on the error messge, it brings me to this line on the
source code.

sortsf(validsf);
Wrong number of arguments.
writeheadings(outfile);
writevalidsf(validsf, outfile);
Wrong number of arguments.
writeinvalidsf(invalidsf, outfile);
Wrong number of arguments.
validsf[i].writetotalsf(outfile);


Fix your prototypes, and provide the correct number of arguments
when calling your functions.

Notes:

1. Note that 'main()' is required to have a return type of 'int'.
Not 'void', or any other type, but 'int'. Only.

2. And finally, when you post code here, please use indentation.
Without, your code is not easy to read.

3. I recommend you consider replacing your arrays with containers
which are more flexible and much less error prone.

HTH,
-Mike
Jul 22 '05 #5
Thank you.

Jul 22 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Tom | last post: by
reply views Thread by Tim21 | last post: by
reply views Thread by Denise L. Moss-Fritch | last post: by
7 posts views Thread by Ron L | last post: by
1 post views Thread by Denise L. Moss-Fritch | last post: by
reply views Thread by Alain \Mbuna\ | last post: by
4 posts views Thread by Stef Mientki | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.