C++ Help
There should be a main program and only 2 functions. the first function should be called 4 times and the name of the divison should be passed to every time it is called. the second function should have 4 divisons sales figures passed to it and return the winning divison. can not use global or reference variables
I took program along time ago. I lost my job and it gave me a chance to go back to school again and i am at a loss all i got was a redo in my email with no explation why maybe some one could help. it is an o/e class done over the net so professor help is out of the question. thanks
#include <iostream>
#include <string>
using namespace std;
class region_stats{
public:
region_stats(float north_east = 0, float south_east = 0, float north_west = 0, float south_west = 0){
division_array[0] = north_east;
division_array[1] = south_east;
division_array[2] = north_west;
division_array[3] = south_west;
}
public: //class functionality
float gen_sale_stats(string &division);
private:
float division_array[4];
};
//simple method of sorting
float region_stats::gen_sale_stats(string &division){
cout << division << endl;
float result = 0;
for (int i = 0; i <= 3; i++) {
if (result < division_array){
result = division_array;
}
}
if(result == division_array[0])
division = "North East";
else if(result == division_array[1])
division = "South East";
else if(result == division_array[2])
division = "North West";
else if(result == division_array[3])
division = "South West";
else (division_array[3],division_array[2],division_array[1],division_array[0]<=0);
//Decides what to return;
return result;
}
int main() {
//Load Varibles into class
float a, b, c, d;
cout << "Enter Sales For north east : ";
cin >> a;
cout << "Enter Sales For south east : ";
cin >> b;
cout << "Enter Sales For north west : ";
cin >> c;
cout << "Enter Sales For south west : ";
cin >> d;
//Call Constructor
region_stats sales_qtr(a, b, c, d);
//Notifying User Of Process:
cout << "generating leading divison and its sales figures for the quarter..." << endl;
//calc func
string div = "";
float results = sales_qtr.gen_sale_stats(div);
cout << "The " << div << " Division, has a total sales figure: " << results << endl;
return 0;
}
I took program along time ago. I lost my job and it gave me a chance to go back to school again and i am at a loss all i got was a redo in my email with no explation why maybe some one could help. it is an o/e class done over the net so professor help is out of the question. thanks
#include <iostream>
#include <string>
using namespace std;
class region_stats{
public:
region_stats(float north_east = 0, float south_east = 0, float north_west = 0, float south_west = 0){
division_array[0] = north_east;
division_array[1] = south_east;
division_array[2] = north_west;
division_array[3] = south_west;
}
public: //class functionality
float gen_sale_stats(string &division);
private:
float division_array[4];
};
//simple method of sorting
float region_stats::gen_sale_stats(string &division){
cout << division << endl;
float result = 0;
for (int i = 0; i <= 3; i++) {
if (result < division_array){
result = division_array;
}
}
if(result == division_array[0])
division = "North East";
else if(result == division_array[1])
division = "South East";
else if(result == division_array[2])
division = "North West";
else if(result == division_array[3])
division = "South West";
else (division_array[3],division_array[2],division_array[1],division_array[0]<=0);
//Decides what to return;
return result;
}
int main() {
//Load Varibles into class
float a, b, c, d;
cout << "Enter Sales For north east : ";
cin >> a;
cout << "Enter Sales For south east : ";
cin >> b;
cout << "Enter Sales For north west : ";
cin >> c;
cout << "Enter Sales For south west : ";
cin >> d;
//Call Constructor
region_stats sales_qtr(a, b, c, d);
//Notifying User Of Process:
cout << "generating leading divison and its sales figures for the quarter..." << endl;
//calc func
string div = "";
float results = sales_qtr.gen_sale_stats(div);
cout << "The " << div << " Division, has a total sales figure: " << results << endl;
return 0;
}
0
Comments
Also, did you try running it before submitting it? There are some helpful (free) tools around to allow you to debug your software.
// displays highest amounts and the name of the highest.
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
const int airlines = 1 ;
int count;
double sales[airlines], // To hold sales amounts
highest; // To hold the highest sales
// Get the sales data.
cout << "Enter the sales for this week.\n";
int array_offset = 0;
for (count = 0; count < airlines; count++)
{
cout << "northeast:";
cin >> sales[count + array_offset];
array_offset++;
cout << "southeast:";
cin >> sales[count + array_offset];
array_offset++;
cout << "northwest:";
cin >> sales[count + array_offset];
array_offset++;
cout << "southwest:";
cin >> sales [count + array_offset];
array_offset++;
}
// Find the highest sales amount.
highest = sales[0];
for (count = 1; count < airlines; count++)
{
if (sales[count] > highest)
highest = sales[count];
}
// Display the results.
cout << fixed << showpoint << setprecision(2);
cout << "The highest sales amount is $" << highest << endl;
return 0;
eg:
[ php ]
#include <iostream>
int main() {
int x = 1;
int y = 2;
char middleInitial = 'B';
return 0;
}
[ /php ]
looks like:
[php]
#include <iostream>
int main() {
int x = 1;
int y = 2;
char middleInitial = 'B';
return 0;
}
[/php]
// displays highest amounts and the name of the highest.
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
const int airlines = 1 ;
int count;
double sales[airlines * 4], // To hold sales amounts
highest; // To hold the highest sales
// Get the sales data.
cout << "Enter the sales for this week.\n";
int array_offset = 0;
for (count = 0; count < airlines; count++)
{
cout << "northeast:";
cin >> sales[count + array_offset];
array_offset++;
cout << "southeast:";
cin >> sales[count + array_offset];
array_offset++;
cout << "northwest:";
cin >> sales[count + array_offset];
array_offset++;
cout << "southwest:";
cin >> sales [count + array_offset];
array_offset++;
}
// Find the highest sales amount.
highest = 0;
for (count = 0; count < airlines; count++)
{
for (int array_var = 0; array_var < 4; array_var++) {
if (sales[array_var + count*4] > highest)
highest = sales[array_var + count*4];
}
cout << "Highest for airline is " << highest<<endl;
highest = 0;
}
return 0;
}
[php]
// displays highest amounts and the name of the highest.
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
const int airlines = 1;
const int t_sales = airlines * 4;
int count;
double sales[t_sales]; // To hold sales amounts
double highest; // To hold the highest sales
// Get the sales data.
cout << "Enter the sales for this week.\n";
for (int count = 0; count < t_sales; count++) {
cout << "northeast:";
cin >> sales[count];
cout << "southeast:";
cin >> sales[count];
cout << "northwest:";
cin >> sales[count];
cout << "southwest:";
cin >> sales [count];
}
// Find the highest sales amount.
highest = 0;
char name[10] = 0;
for (count = 0; count < t_sales; count++) {
if (sales[count] > highest) {
switch (count) {
case 1: name = "northeast"; break;
case 2: name = "southeast"; break;
case 3: name = "northwest"; break;
case 4: name = "southwest"; break;
}
highest = sales[count];
}
}
cout << "Highest for" << name << " is " << highest << endl;
return 0;
}
[/php]
But keep getting an error at char name[10] = 0;
for (count = 0; count < t_sales; count++) {
C:\Program Files\Microsoft Visual Studio\MyProjects\cpp(33) : error C2440: 'initializing' : cannot convert from 'const int' to 'char [10]'
any one know what wrong with it.
You can ignore the assignment, its not nescessary. just use:
[PHP]
char name[10];
[/PHP]
also in the next section you might need to change the
[PHP]name = "northeast";[/PHP]
etc ...
to
[PHP]strcpy (name, "northeast");[/PHP]
and so on..
?? hey, i think it was html rendering that was taking his header file reference out because html is turned on, cause it just took mine out. lemme post it with the php tag.
[PHP]#include <iostream.h>
#include <iomanip.h>[/PHP]
Enter the sales for this week
northeast:23
southeast:45
northwest:56
southwest:567
northeast:55
southeast:456
northwest:456
southwest:4567
northeast:5676
southeast:56
northwest:43
southwest:456
northeast:455
southeast:67
northwest:554
southwest:56
Highest fornortheast is 0
Press any key to continue
thanks every one for the help
M
[PHP]cout << "Highest for" << name << " is " << highest << endl;[/PHP]
should look like this:
[PHP]cout << "Highest for " << name << " is " << highest << endl;[/PHP]
I'll look at the actuall code now, instead of just fixing the output statement.
This asks for the 4 divisions figures and returns the winner. Im confused as to why you'd have to call the first function four times though as the switch takes care of the actual naming .. if this isnt what you need post back and let me know.
[PHP]
#include <iostream>
using namespace std;
class region_stats{
public:
region_stats(float north_east = 0, float south_east = 0, float north_west = 0, float south_west = 0){
division_array[0] = north_east;
division_array[1] = south_east;
division_array[2] = north_west;
division_array[3] = south_west;
}
public: //class functionality
float gen_sale_stats(char* &division);
private:
float division_array[4];
};
//simple method of sorting
float region_stats::gen_sale_stats(char* &division){
cout << division << endl;
float result = 0;
for (int i = 0; i <= 3; i++) {
if (result < division_array){
result = division_array;
}
}
if(result == division_array[0])
division = "North East";
else if(result == division_array[1])
division = "South East";
else if(result == division_array[2])
division = "North West";
else if(result == division_array[3])
division = "South West";
else (division_array[3],division_array[2],division_array[1],division_array[0]<=0);
//Decides what to return;
return result;
}
int main() {
//Load Varibles into class
float a, b, c, d;
cout << "Enter Sales For north east : ";
cin >> a;
cout << "Enter Sales For south east : ";
cin >> b;
cout << "Enter Sales For north west : ";
cin >> c;
cout << "Enter Sales For south west : ";
cin >> d;
//Call Constructor
region_stats sales_qtr(a, b, c, d);
//Notifying User Of Process:
cout << "generating leading divison and its sales figures for the quarter..." << endl;
//calc func
char* div = "";
float results = sales_qtr.gen_sale_stats(div);
cout << "The " << div << " Division, has a total sales figure: " << results << endl;
return 0;
}
[/PHP]
is that directed at me? I dont think they are ..
edit:// looks like youre talking about a2j's code ... thats a good question, theres no reason for it given the parameters