•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 456,573 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,583 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 733 | Replies: 14
![]() |
•
•
Join Date: Oct 2007
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 0
I have been given a problem that asks me to do the following things. Write a program should be stored in two dimensional array. The program must include the following
1. list 4 qtrly sales for 6 divisions of a company.
2. show each division increase or decrease from the previous qtr
3. total the sales for the qtr
4. show the companys increase or decrease from previous qtr...excluding the first qtr.
5. average sales for all divisions that qtr
6. list the division with the highest sales for that qtr.
**now I understand that this is just a site that offers assistance with problems and I must be willing to work as well...so this is what I know...
that the firs size declarator would pertain to the number of rows and the second one is for the number of columns. I also know and understand that a two dimensional array has 2 subscripts...but it all gets a little mirky after that...please help
1. list 4 qtrly sales for 6 divisions of a company.
2. show each division increase or decrease from the previous qtr
3. total the sales for the qtr
4. show the companys increase or decrease from previous qtr...excluding the first qtr.
5. average sales for all divisions that qtr
6. list the division with the highest sales for that qtr.
**now I understand that this is just a site that offers assistance with problems and I must be willing to work as well...so this is what I know...
that the firs size declarator would pertain to the number of rows and the second one is for the number of columns. I also know and understand that a two dimensional array has 2 subscripts...but it all gets a little mirky after that...please help
You're absoluately right. We won't give you a complete code, but we'll help and provide pointers. Firstly, welcome aboard. I can give you a head start, although i wish you'd read up on arrays. You need to tell us if the program is doing to be interactive, will it read data from the infile???
A few things:
1. You can start by delcaring a few variables that you'll need:
2. With regards to the six divisions...for example, if it's the same company, they perhaps are divided as such:
3. Then for the arrays, you may do something like:
4. Create a titles/headers to show your output data:
5. Use a FOR loop to go through each division.
6. Do calculation to carry out the averages.
Hope this helps, I know that C++ at times may be overwhelming, but write it out on scratch-paper first to see exactly what you'll need to do. I gave you a jumpstart. You'll also need to provide more information about the requirements of your assignment.
A few things:
1. You can start by delcaring a few variables that you'll need:
struct Comp; float first; float second; float third; float value; float average;
string const N = "North Division"; string const S = "South Division"; string const E = "East Division"; string const W = "West Division";
Comp div[4] div [0].name= N; div [1].name= S; div [2].name= E; div [3].name= W;
cout<<setw(10)<<"Division"<<setw(15)<<"First Quarter"<<setw(15)<<"Second Quarter"<<setw(15)<<"Third Quarter"<<setw(15)<<"Fourth Quarter"<<setw(15)<<"Total"<<setw(15)<<"Average"<<endl;
6. Do calculation to carry out the averages.
Hope this helps, I know that C++ at times may be overwhelming, but write it out on scratch-paper first to see exactly what you'll need to do. I gave you a jumpstart. You'll also need to provide more information about the requirements of your assignment.
•
•
Join Date: Oct 2007
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 0
this is what I have so far
1 //This program demonstrates a two-dimensional array.
2 #include <iostream>
3 #include <iomanip>
4 using name space std;
5
6 int main()
7 {
8 const int NUM_DIVS=6; //Number of divisions
9 const int NUM_QTRS =4; //Number or quaters
10 double sales [NUM_DIVS] [NUM_QTRS]; //Array with 6 rows and 4 columns.
11 double totalSales = 0; //To hold the total sales.
12 int div, qtr; // Loop counters.
1 //This program demonstrates a two-dimensional array.
2 #include <iostream>
3 #include <iomanip>
4 using name space std;
5
6 int main()
7 {
8 const int NUM_DIVS=6; //Number of divisions
9 const int NUM_QTRS =4; //Number or quaters
10 double sales [NUM_DIVS] [NUM_QTRS]; //Array with 6 rows and 4 columns.
11 double totalSales = 0; //To hold the total sales.
12 int div, qtr; // Loop counters.
You'll also need the following header for mathematical calculations(averages..ect...)
#include <cmath>
•
•
Join Date: Oct 2007
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 0
1 //This program demonstrates a two-dimensional array.
2 #include <iostream>
3 #include <iomanip>
4 #include <cmath>
5 using name space std;
6 int main()
7 {
8 const int NUM_DIVS=6; //Number of divisions
9 const int NUM_QTRS =4; //Number or quaters
10 double sales [NUM_DIVS] [NUM_QTRS]; //Array with 6 rows and 4 columns.
11 double totalSales = 0; //To calculate the total sales.
12 int div, qtr; // Loop counters.
13
14 cout <<"This program will calculate the total sales of \n";
15 cout<<"all th4e company's divisions.\n";
16 cout <<"Enter the following sales information:\\n\n";
17
18 //Nested loops to fill the array with quaterly
19 //sales figures for each division
20 for (div = 0 ; div< NUM_DIVS; div++)
{
[/code][/quote]
2 #include <iostream>
3 #include <iomanip>
4 #include <cmath>
5 using name space std;
6 int main()
7 {
8 const int NUM_DIVS=6; //Number of divisions
9 const int NUM_QTRS =4; //Number or quaters
10 double sales [NUM_DIVS] [NUM_QTRS]; //Array with 6 rows and 4 columns.
11 double totalSales = 0; //To calculate the total sales.
12 int div, qtr; // Loop counters.
13
14 cout <<"This program will calculate the total sales of \n";
15 cout<<"all th4e company's divisions.\n";
16 cout <<"Enter the following sales information:\\n\n";
17
18 //Nested loops to fill the array with quaterly
19 //sales figures for each division
20 for (div = 0 ; div< NUM_DIVS; div++)
{
[/code][/quote]
At the begining of your code place:
"["CODE=cplusplus"]", without the ". This way its easier to read...back to your assignment....
Given the requirement of your assignment, you may want to break down your program a bit more...example:
"["CODE=cplusplus"]", without the ". This way its easier to read...back to your assignment....
•
•
•
•
16 cout <<"Enter the following sales information:\\n\n";
cplusplus Syntax (Toggle Plain Text)
cout<< "Please enter First Qrt Sales"<<div[j].name<<endl; cin>>div[j].fir; cout<< "Please enter Second Qrt Sales"<<div[j].name<<endl; cin>>div[j].sec; cout<< "Please enter Third Qrt Sales"<<div[j].name<<endl; cin>>div[j].thir; cout<< "Please enter Fourth Qrt Sales"<<div[j].name<<endl; cin>>div[j].four;
•
•
Join Date: Jul 2005
Posts: 1,288
Reputation:
Rep Power: 9
Solved Threads: 175
OK, now use a nested loop to enter data into array. Here's a very basic outline of a nested loop using for loops. You have to fill in the necessary details as per your project instructions.
for() //this loop will control which row you're using
{
for() //this loop will control which column you're using.
{
}
}![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Commission Sales People (Internet Marketing Job Offers)
- Getting Your Site Submitted to Search Engines (Search Engine Optimization)
- Best way to advertise – Revealed by a 1920s Classic. (Advertising Sales Strategies)
- National Accounts Manager NEEDED! (Tech / IT Consultant Job Offers)
- AdSense now offers detailed statistics! (Advertising Sales Strategies)
- 500MB's/20 GB's - $8.95 ~~~ 1000MB's/40GB's - $14.95 + 1 Month FREE! (Web Hosting Deals)
- Statistics tracker? (Linux Servers and Apache)
Other Threads in the C++ Forum
- Previous Thread: Problem with vectors
- Next Thread: Inheritance



Linear Mode