C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old March 15th, 2004, 06:40 PM
mikey12784 mikey12784 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: current Eau Claire
Posts: 4 mikey12784 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy Hey guys, just signed up today and i need some C++ help

HEY! as you can tell probably my names mike . im a huge hardware nut, but i thought hey, might as well expand the horizons and try out some programming to complete my knowledge about computer stuff. BIG MISTAKE. i try and i try, but i am not very good @ this stuff at all. I would MUCH appreciate if you guys could assist me in my programming assignment. I dont know really what to do other than post the assignment, so here goes

Overall Task:

Write a program that uses functions to calculate the smallest, largest, average (mean), variance and standard deviation for a file of values (can be integer or floating point). Display the results of this to an output file.



Background:

Given a set of numbers, you can compute many statistics on them. Easiest to understand are values such as the smallest (minimum) and largest (maximum). There are other statistics such as the mean (average), the median (the number(s) that is/are physically in the middle of the sorted list of the numbers, the mode (the most common value(s)), and the variance and standard deviation (measures of how close the set of values are to each other).



Specific Tasks: // THERE MUST BE 7 FUNCTIONS

Write a program that does the following:

· Asks the user for an input file name and output file name

· Processes the values in the file to calculate the

o Maximum

o Minimum

o Mean

o Variance

o Standard Deviation

for this set of numbers.

Note: you can process the input file as many times as you need to.



Formulas:

Variance = (Sum of (each value – mean) for all values) / mean

Standard Deviation = Square root of the variance



You must have at least seven functions that do the following:

· Input the filenames (we’ll talk more about how to store these)

· Calculate each of the five statistics above (i.e. five functions)

· Output all five statistics

Think about what parameters and return types you need for each function.



If you want to add additional functions for other tasks, you’re welcome to do so.



Other Requirements:

Good programming style must be used (as discussed in class and stated in the programming guidelines on the class web page)



Testing:

Test your program with several different files. For grading, we’ll test it with some more. Make sure it works with all cases (empty files, small files, large files, ordered files, unordered files, values of different data types, etc.). Sample data files will be added to this page shortly to show you the possible format, but you can certainly create your own data files with a text editor like WordPad. All data files should have one value per line.



Hand In:

Drop your source code file entitled Files-<username>.cpp into the Assignments folder (e.g. Files-wagnerpj.cpp for me). Please use EXACTLY this format – it makes grading these easier (up to -5 points this time if you don’t).



Extra Credit:

Calculate the mode(s) and/or median(s) as well. Again, note that there may be one or more of each of these. Since this involves multiple values, you may make functions that calculate and output these for now (later on, we’ll look at how to use arrays to hold and pass around multiple values like this).

Reply With Quote
  #2  
Old March 16th, 2004, 05:23 AM
Spongy's Avatar
Spongy Spongy is offline
Alternately High
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Hilversum, Netherlands
Posts: 223 Spongy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 56 m 41 sec
Reputation Power: 5
Send a message via MSN to Spongy
Look like a school assignment to me...
Why don't you just grab a book and make your homework yourself
__________________
Work to live, don't live to work

Reply With Quote
  #3  
Old March 16th, 2004, 06:25 AM
Izkata Izkata is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 6 Izkata User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Try doing this: Go into the main() function and start typing in what's going on in the "Overall Task", using, erm... whichever lang. you're using.

It seems overwhelming at first, but simply focus on one part at a time and you'll get it.

Reply With Quote
  #4  
Old March 16th, 2004, 07:26 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Mike, you won't get much help if you just paste in your assignment. Take a stab at it and post specific questions in here when you hit a roadblock. If your teacher hasn't given you the resources (a book, for example, or some code samples or other handouts) to get started with, complain to the dean.
__________________
Please don't PM me asking for solutions outside the scope of a thread.
Keeping all responses in a thread stands to help others who come along later,
which is after all what this forum's all about.

Reply With Quote
  #5  
Old March 18th, 2004, 04:29 PM
mikey12784 mikey12784 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: current Eau Claire
Posts: 4 mikey12784 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Alrighty guys, got a fairly good start here, i would appreciate any tips/advice on what you think i need/should add to this, and if you see any mistakes as of now, will post more in a few hours


/*Program 3 CS 163: Writing and Reading Data from files that uses functions to calculate the smallest,
largest, average (mean), variance and standard deviation for a
file of values (can be integer or floating point).
Display the results of this to an output file.
Created by: Michael Davenport
Creation date: March 12, 2004.
modified : march 15, 2004
*/

#include <iostream> //for general input/output
#include <cmath> // for math calculations
#include <fstream> // for file input/output
using namespace std;
//Function Declaration area
void enter_filename (char infilename[30], char outfilename[30]); //Function that gets filename
double find_maximum(char infilename[30]); //Function that finds highest number
double find_minimum(char infilename[30]); //Function that finds lowest number
double find_mean(char infilename[30]); //Function that calculates the mean
double find_variance(char infilename[30]); //Function that calculates the variance
double find_std_deviation(char infilename[30]): //Function that calculates the std. deviation
void write_to_file(char outfilename[30], char outfilename[30]); //Function that writes information back to file



int main ()
{

//Variables

ifstream instream; // input file stream
char infilename[30]; // name of actual input file
char outfilename[30]; // Name of file to be outputed or created
double max;
double min;
double mean;
double variance;
double std_dev;

cout.setf(ios::fixed); // Allows #'s
cout.setf(ios::showpoint); //
cout.precision(3); // Allows three numerical values beyond decimal point



instream.open(infilename);
if (instream.fail())
{
cout << "Cannot open file " << infilename << endl;
exit(1);
}

// Area to call functions

enter_filename (char infilename[30], char outfilename[30]); //Function that gets filename
cout<< endl << "The name of the file to be input into the program is;" << infilename << endl;
find_maximum(char infilename[30]); //Function that finds highest number
cout<< "The highest number in the file is; " << max << endl;
find_minimum(char infilename[30]); //Function that finds lowest number
cout<< "The lowest number in the file is; " << min << endl;
find_mean(char infilename[30]); //Function that calculates the mean
cout<< "The average or mean of the numbers in: " << infilename << "is" << mean << endl;
find_variance(char infilename[30]); //Function that calculates the variance
cout<< "The variance of the numbers in: " << infilename << "is" << variance << endl;
find_std_deviation(char infilename[30]): //Function that calculates the std. deviation
cout<< "The Standard Deviation of the numbers in: " << infilename << "is" << std_dev << endl;
write_to_file(char outfilename[30], char outfilename[30]); //Function that writes information back to file
cout<< "The file:" << outfilename << "has been created" << endl;
return (0);
// Function Definitions area

Reply With Quote
  #6  
Old March 18th, 2004, 07:48 PM
mikey12784 mikey12784 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: current Eau Claire
Posts: 4 mikey12784 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
grr. having some troubles here:

enter_filename (char infilename[30], char outfilename[30]); //Function that gets filename
cout<< endl << "The name of the file to be input into the program is;" << infilename << endl;
find_maximum(char infilename[30]); //Function that finds highest number
cout<< "The highest number in the file is; " << max << endl;
find_minimum(char infilename[30]); //Function that finds lowest number
cout<< "The lowest number in the file is; " << min << endl;
find_mean(char infilename[30]); //Function that calculates the mean
cout<< "The average or mean of the numbers in: " << infilename << "is" << mean << endl;
find_variance(char infilename[30]); //Function that calculates the variance
cout<< "The variance of the numbers in: " << infilename << "is" << variance << endl;
find_std_deviation(char infilename[30]): //Function that calculates the std. deviation
cout<< "The Standard Deviation of the numbers in: " << infilename << "is" << std_dev << endl;
write_to_file(char outfilename[30], char outfilename[30]); //Function that writes information back to file
cout<< "The file:" << outfilename << "has been created" << endl;
return (0);
// Function Definitions area

void enter_filename (char infilename[30], char outfilename[30]); //Function that gets filename
{
cout<< "Enter the name of the including any dot (.) extensions: " ;
cin>> infilename;
cout<< endl << "Enter the name of the file to be created for output";
cin>> outfilename;
}
double find_maximum(char infilename[30]); //Function that finds highest number
{

double value;
double maximum = -9999;

instream.open (infilename);
while (!instream.eof());
{
instream >> value;
if ( value > max )
{
maximum = value;
}
}
instream.close();
return maximum;
}
double find_minimum(char infilename[30]); //Function that finds lowest number
{

double value;
double minimum = 9999;

instream.open (infilename);
while (!instream.eof())
{
instream >> value;
if (value = minimum)
{
minimum = value;
}
}
instream.close();
return minimum;
}

double find_mean(char infilename[30]); //Function that calculates the mean
{
double sum = 0;
double next_value;
int count = 0;

instream.open (infilename);
while (!instream.eof());
{
instream >> next_value;
sum += next_value;
count ++;
}
double mean = sum / count;
instream.close();
return mean;
}

double find_variance(char infilename[30]); //Function that calculates the variance
{
double sum = 0;
double next_value;
int count = 0;
double mean = find_mean (infilename);

while (!instream.eof())
{
instream >> next_value;
sum += pow( next_value - mean, 2 );
count++;
}
double variance = sum / count;
instream.close();
return variance;
}
double find_std_deviation(char infilename[30]); //Function that calculates the std. deviation
{
double variance = find_variance(infilename);
return sqrt(variance);
}
void write_to_file(char infilename[30], char outfilename[30]); //Function that writes information back to file
{
ofstream outstream;
outstream.open (outfilename);
if ( outstream.fail())
{
cout<< "There was an error writing data to an outfile." << endl;
exit ( 1 );
}
}
outstream << "The maximum number in the file is:"
<< find_maximum(infilename);
outstream << "The minimum number in the file is:"
<< find_minimum(infilename);
outstream << "The mean or average of the numbers in the file is: "
<< find_mean(infilename);
outstream << "The variance from the file is:"
<< find_variance(infilename);
outstream << "The standard deviation of the file is: "
<< find_std_deviation(infilename);
outstream.close(); // closes the stream

}

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Hey guys, just signed up today and i need some C++ help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway