Re: Help w/ c++ assignment...
I know why your post hasn't received much response, and I'm sorry to say this but, we've seen a few requests for a statistician class around here, we know you want help with homework but collectively we have an ethic of not 'doing' homework for anyone.
What you've posted is like the table of contents, and now have requested that we start writing the story.
To get help, you'll need to try to create a function - ask questions about that function(s) you're trying to write, but something less obvious than "what do I do?"
For example....
// double minimum( ) const
// Precondition: length( ) > 0
// Postcondition: The return value is the tinyest number in the
// statistician's sequence.
It seems you must ensure that the length() > 0. If it's not, what would you do?
How would you find the 'tinyest' number in the sequence?
Can you start out doing that?
Is there a simpler function you can take a running start at?
Re: Help w/ c++ assignment...
Additionally, your chances of getting a reply increase, if you read some of the rules for posting, e.g. the one about [code] tags.
Re: Help w/ c++ assignment...
hah I remember doing this program years ago!
Probably same book too,
main_savitch_2C namespace.
Re: Help w/ c++ assignment...
Re: Help w/ c++ assignment...
First thing that comes to mind is for the constructor you have there in that outline header file you're gonna need to put in a simple destructor method.
That's pretty much the simplest thing you'll have to do.
Re: Help w/ c++ assignment...
Quote:
Originally Posted by goatslayer
First thing that comes to mind is for the constructor you have there in that outline header file you're gonna need to put in a simple destructor method.
No. The automatically generated destructor will do fine.
One thing you should ask you lector is why count is defined as signed int? And why is the variable called count but the function is called length? Are these supposed to be different things?
Re: Help w/ c++ assignment...
Quote:
Originally Posted by treuss
No. The automatically generated destructor will do fine.
One thing you should ask you lector is why count is defined as signed int? And why is the variable called count but the function is called length? Are these supposed to be different things?
I thought if you explicitly set up a constructor then you explicitly had to set up a destructor?
Re: Help w/ c++ assignment...
Quote:
Originally Posted by goatslayer
I thought if you explicitly set up a constructor then you explicitly had to set up a destructor?
Nope. No such rule. There is a rule-of-thumb, that if you need to define a copy-constructor you will probably also need to define a destructor and an assignement operator. Likewise, if you need to define a non-empty destructor (you might define an empty destructor just to have it virtual), you will probably also need the other two. This however is not a rule of the C++ language, rather a rule that newbees should keep in mind.
Re: Help w/ c++ assignment...
I think the rule you're probably thinking of is if you provide any type of constructor, the compiler will not auto-generate the default constructor for you:
Code:
class Foo
{
public:
Foo(int someNum) : m_Num(someNum) {}
private:
int m_Num;
};
int main()
{
Foo myFoo; // Should throw a compile error
}
Viggy
Re: Help w/ c++ assignment...
Hi All.. I need help.
Below is the stats.cpp file for which I am getting errors. I mainly am having problems with operator +, *, ==. I have also pasted the errors. Please help me, I am confused!
Notice, I have to declare my doubles' again or else it states: undeclared.
Code:
/***********************
Purpose:
Statistician class...
************************/
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <string.h>
#include <iomanip>
#include <cfloat>
#include "stats.h"
using namespace std;
namespace stat
{
class statistician
{
double last;//why do i have to declare again?
double count;// header file has all these
double total;
double tiniest;
double largest;
double s;
statistician::statistician()
{
reset();
}
void statistician::reset()
{
total = count = 0;
tiniest = DBL_MIN;
largest = DBL_MAX;
}
...
errors:
--------------------Configuration: stats - Win32 Debug--------------------
Compiling...
stats.cpp
C:\Documents and Settings\Gagan\My Documents\Documents\Data Structures\stats\stats\stats.cpp(117) : error C2228: left of '.total' must have class/struct/union type
C:\Documents and Settings\Gagan\My Documents\Documents\Data Structures\stats\stats\stats.cpp(118) : error C2228: left of '.tiniest' must have class/struct/union type
C:\Documents and Settings\Gagan\My Documents\Documents\Data Structures\stats\stats\stats.cpp(118) : error C2228: left of '.tiniest' must have class/struct/union type
C:\Documents and Settings\Gagan\My Documents\Documents\Data Structures\stats\stats\stats.cpp(119) : error C2228: left of '.largest' must have class/struct/union type
C:\Documents and Settings\Gagan\My Documents\Documents\Data Structures\stats\stats\stats.cpp(119) : error C2228: left of '.largest' must have class/struct/union type
C:\Documents and Settings\Gagan\My Documents\Documents\Data Structures\stats\stats\stats.cpp(120) : error C2228: left of '.count' must have class/struct/union type
C:\Documents and Settings\Gagan\My Documents\Documents\Data Structures\stats\stats\stats.cpp(132) : error C2660: 'maximum' : function does not take 0 parameters
C:\Documents and Settings\Gagan\My Documents\Documents\Data Structures\stats\stats\stats.cpp(132) : error C2660: 'maximum' : function does not take 0 parameters
C:\Documents and Settings\Gagan\My Documents\Documents\Data Structures\stats\stats\stats.cpp(134) : error C2660: 'minimum' : function does not take 0 parameters
C:\Documents and Settings\Gagan\My Documents\Documents\Data Structures\stats\stats\stats.cpp(134) : error C2660: 'minimum' : function does not take 0 parameters
C:\Documents and Settings\Gagan\My Documents\Documents\Data Structures\stats\stats\stats.cpp(143) : warning C4305: 'return' : truncation from 'const int' to 'bool'
Error executing cl.exe.
stats.exe - 10 error(s), 1 warning(s)
Re: Help w/ c++ assignment...
The answer to your question "why do i have to declare again?" is "You don't!".
The errors you are getting are due to the facts that you define everything inside the class statician. The class itself should be declared in the header file (stats.h). If that is done (according to your original post), just drop the following (and the corresponding closing brace) from the file:
Code:
class statistician
{
double last;//why do i have to declare again?
double count;// header file has all these
double total;
double tiniest;
double largest;
double s;
class or namespace error..need compiling help!!
Why do I get an error: "statistician is not a class or namespace name?"
What do I need to use for assert?
Why is their a syntax error for operator + () ??
Code:
stats.h file
Code:
#ifndef STATS_H // Prevent duplicate definition
#define STATS_H
#include <iostream>
namespace CISP430_A1
{
class statistician
{
//rest of code
stats.cpp file
Code:
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <string.h>
#include <iomanip>
using namespace std;
#include "STATS.H"
statistician::statistician()
{
reset();
}
//rest of code
I am not using any makefile. I am just using my Visual Studio C++ and I have a test file with int main ().
Code:
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <string.h> // Provides memcpy function
#include "stats.h"
using namespace CISP430_A1;
using namespace std;
const int SCORE0=0,SCORE1=90, SCORE2=15;
bool close(double a, double b)
{
const double EPSILON = 1e-5;
return (fabs(a-b) < EPSILON);
}
int test1( )
//rest of code
Please let me know why its not seeing the class statistician and header file things.
Errors:
--------------------Configuration: stats - Win32 Debug--------------------
Compiling...
stats.cpp
C:\Documents and Settings\Gagan\My Documents\Documents\Data Structures\stats\stats\stats.cpp(23) : error C2653: 'statistician' : is not a class or namespace name
C:\Documents and Settings\Gagan\My Documents\Documents\Data Structures\stats\stats\stats.cpp(25) : error C2065: 'reset' : undeclared identifier
C:\Documents and Settings\Gagan\My Documents\Documents\Data Structures\stats\stats\stats.cpp(26) : warning C4508: 'statistician' : function should return a value; 'void' return type assumed
C:\Documents and Settings\Gagan\My Documents\Documents\Data Structures\stats\stats\stats.cpp(28) : error C2653: 'statistician' : is not a class or namespace name
C:\Documents and Settings\Gagan\My Documents\Documents\Data Structures\stats\stats\stats.cpp(30) : error C2065: 'total' : undeclared identifier
C:\Documents and Settings\Gagan\My Documents\Documents\Data Structures\stats\stats\stats.cpp(31) : error C2065: 'count' : undeclared identifier
C:\Documents and Settings\Gagan\My Documents\Documents\Data Structures\stats\stats\stats.cpp(32) : error C2065: 'tiniest' : undeclared identifier
C:\Documents and Settings\Gagan\My Documents\Documents\Data Structures\stats\stats\stats.cpp(33) : error C2065: 'largest' : undeclared identifier
C:\Documents and Settings\Gagan\My Documents\Documents\Data Structures\stats\stats\stats.cpp(35) : error C2653: 'statistician' : is not a class or namespace name
C:\Documents and Settings\Gagan\My Documents\Documents\Data Structures\stats\stats\stats.cpp(36) : error C2373: 'reset' : redefinition; different type modifiers
C:\Documents and Settings\Gagan\My Documents\Documents\Data Structures\stats\stats\stats.cpp(42) : error C2653: 'statistician' : is not a class or namespace name
C:\Documents and Settings\Gagan\My Documents\Documents\Data Structures\stats\stats\stats.cpp(43) : error C2270: 'length' : modifiers not allowed on nonmember functions
C:\Documents and Settings\Gagan\My Documents\Documents\Data Structures\stats\stats\stats.cpp(47) : error C2653: 'statistician' : is not a class or namespace name
C:\Documents and Settings\Gagan\My Documents\Documents\Data Structures\stats\stats\stats.cpp(48) : error C2270: 'sum' : modifiers not allowed on nonmember functions
C:\Documents and Settings\Gagan\My Documents\Documents\Data Structures\stats\stats\stats.cpp(52) : error C2653: 'statistician' : is not a class or namespace name
C:\Documents and Settings\Gagan\My Documents\Documents\Data Structures\stats\stats\stats.cpp(53) : error C2270: 'mean' : modifiers not allowed on nonmember functions
C:\Documents and Settings\Gagan\My Documents\Documents\Data Structures\stats\stats\stats.cpp(54) : error C2065: 'assert' : undeclared identifier
C:\Documents and Settings\Gagan\My Documents\Documents\Data Structures\stats\stats\stats.cpp(58) : error C2653: 'statistician' : is not a class or namespace name
C:\Documents and Settings\Gagan\My Documents\Documents\Data Structures\stats\stats\stats.cpp(58) : error C2143: syntax error : missing ',' before '&'
C:\Documents and Settings\Gagan\My Documents\Documents\Data Structures\stats\stats\stats.cpp(58) : error C2059: syntax error : '&'
C:\Documents and Settings\Gagan\My Documents\Documents\Data Structures\stats\stats\stats.cpp(64) : error C2653: 'statistician' : is not a class or namespace name
C:\Documents and Settings\Gagan\My Documents\Documents\Data Structures\stats\stats\stats.cpp(64) : error C2143: syntax error : missing ',' before '&'
C:\Documents and Settings\Gagan\My Documents\Documents\Data Structures\stats\stats\stats.cpp(64) : error C2059: syntax error : '&'
C:\Documents and Settings\Gagan\My Documents\Documents\Data Structures\stats\stats\stats.cpp(71) : error C2143: syntax error : missing ';' before '+'
C:\Documents and Settings\Gagan\My Documents\Documents\Data Structures\stats\stats\stats.cpp(71) : error C2501: 'statistician' : missing storage-class or type specifiers
C:\Documents and Settings\Gagan\My Documents\Documents\Data Structures\stats\stats\stats.cpp(71) : error C2373: 'statistician' : redefinition; different type modifiers
C:\Documents and Settings\Gagan\My Documents\Documents\Data Structures\stats\stats\stats.cpp(23) : see declaration of 'statistician'
C:\Documents and Settings\Gagan\My Documents\Documents\Data Structures\stats\stats\stats.cpp(71) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
stats.exe - 26 error(s), 1 warning(s)
As Always, thanks!
Re: class or namespace error..need compiling help!!
Quote:
Originally Posted by GaganW18
Why do I get an error: "statistician is not a class or namespace name?"
Because you declared statistician to be in namespace CISP430_A1. So it's name is CISP430_A1::statistician (unless you import that namespace), i.e. you should define your constructor
Code:
CISP430_A1::statistician::statistician() {...}
Quote:
Originally Posted by GaganW18
What do I need to use for assert?
include <cassert>
Quote:
Originally Posted by GaganW18
Why is their a syntax error for operator + () ??
Probably because it does not know what statistician is. Qualify it with the name of the namespace or import the namespace.
Re: Help w/ c++ assignment...
I've been working through a few complex C++ assignments myself lately, and this discussion really helped me understand how to manage memory more efficiently. For anyone who's still learning or stuck with university tasks, exploring some reliable C++ assignment help resources or examples can make a big difference ? especially for handling pointers and class structures correctly. Thanks to everyone here for keeping such detailed threads active; they're genuinely useful for both students and developers trying to polish their coding skills.
**Links removed by Site Administrator so it doesn't look like you're spamming us. Please don't post them again.**
Re: Help w/ c++ assignment...
Quote:
Originally Posted by
scottburke464
I've been working through a few complex C++ assignments myself lately, and this discussion really helped me understand how to manage memory more efficiently. For anyone who's still learning or stuck with university tasks, exploring some reliable C++ assignment help resources or examples can make a big difference ? especially for handling pointers and class structures correctly. Thanks to everyone here for keeping such detailed threads active; they're genuinely useful for both students and developers trying to polish their coding skills.
**Links removed by Site Administrator so it doesn't look like you're spamming us. Please don't post them again.**
Dude, this thread is 18 years old...:ehh: