473,406 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 2810

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Tom | last post by:
A question for gui application programmers. . . I 've got some GUI programs, written in Python/wxPython, and I've got a help button and a help menu item. Also, I've got a compiled file made with...
0
by: Tim21 | last post by:
OK, im miserable :)) so.. help'd b highly appreciated. Situation: Win XP aplication server RUNTIME (stored fmx files along with the ..hlp files) Fmx's generated and compiled on development...
0
by: Denise L. Moss-Fritch | last post by:
Has anyone developed context sensitive help for a C# application? According to our programming staff, the development side is not able to provide links without adding hard coded links (topic names)...
2
by: clintonG | last post by:
Is there a document that explains the difference between the Visual Studio .NET 2003 Combined Help Collection and the MSDN Library for Visual Studio .NET 2003 or does someone have comments...
7
by: Ron L | last post by:
I am at the beginning of a new project, and want to have my developers work on the Help files as we are developing the new application forms. Since most of my previous work has been in the ASP...
3
by: Mark Lees | last post by:
Just installed 2003 and the help file sucks because it tries to connect to Microsoft Online Help which takes too long. When I run Access and I'm not connected to the internet, it seems to connect...
5
by: TD | last post by:
Hey All, I am hooking up our custom html (.chm) help file to our Access xp application, and, despite reading several posts and manuals on this, I still have a gap in my understanding... OK, so...
1
by: Denise L. Moss-Fritch | last post by:
Has anyone developed context sensitive help for a C# application? According to our programming staff, the development side is not able to provide links without adding hard coded links (topic names)...
0
by: Alain \Mbuna\ | last post by:
Hi to you all. As a beginning programmer, I finally succeeded in finishing my first application. I made the application with VB expr 2005 and provided the application with a help project, which...
4
by: Stef Mientki | last post by:
I'm making special versions of existing functions, and now I want the help-text of the newly created function to exists of 1. an extra line from my new function 2. all the help text from the old...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.