Solving problem .

Jun 13, 2018 at 12:00am
hey guys
I have the assignment below to submit really soon but I can't figure out what the program what me to do

I have tried to display the numbers from the chart by copying them into file but it didn't work

please any advice will be appreciated








Assignment Description:
In this assignment you will develop a C++ program for a property management company that uses files and nested loops to write to a file and read from a file. The program will calculate total rent collected for the company, average rent collected per month for the company, display the highest grossing complex, and displays a warning message if zero rent was entered for any of the complexes.

Main 2000 1000 3000 2000 2000
Clay 3000 5000 4000 5000 4000
King 2000 2000 4000 2000 0

Requirements
1. Use a nested loop structure to input the data and write the data to a text file. Use the data in the chart above to test your program. The user will enter the number of months to be processed.
2. Use a nested loop to read and display the data from the text files.
a. Display the data that is stored on the file.
b. Calculate and display total rent collected for the company.
c. Calculate and display the average monthly rent collected for the company.
d. Display the complex with the highest amount of total rent collected.
e. Use a Boolean variable to flag if any of the months had zero income. Print a warning message to request a company audit.
3. Use cout to output the values of the variables to the console. Your cout statement MUST use the variables to display the values
4. Output must be labelled and easy to read as shown in the sample output below.
5. Program must be documented with the following:
a. // Name
b. // Date
c. // Program Name
d. // Description


Jun 13, 2018 at 2:41am
It would be nice to provide some code to let us see where you are at. But since you did not, I'm going to assume that you haven't gotten very far.

I have tried to display the numbers from the chart by copying them into file but it didn't work

Not sure what you mean by this. Have you tried reading them in and storing them inside a struct? (Or your choice of organization).

Start coding your project, but begin with small steps. Implement small functions that do what they are meant to do. This means you should practice modularity. Build the smaller pieces, then see how you can fit those smaller pieces to form your program.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <fstream>
#include <string>

// I'll give you a hint on how to read from the file.
// Ok, so you know the file is formatted like this:
//
//      Name # # # # #
//
// Where each # represents some number. That means the first thing you should
//   read from the file is a string and the next five things should be an
//   integer. While writing your code, you will want to consider how you want to
//   store the information you are reading. We can do that with a simple struct.

struct personInformation
{
    std::string personName;
    int number[5]; // Since there are five numbers.
};

void readInformationFromFile(personInformation []) // This function reads and stores information
{
    const std::string fileName = "info.dat";
    std::ifstream inFile(fileName.c_str()); // Open the file
    
    // Some code here on how to read...
    // Some code here on how to store...
    // Some code here on how to whatever...
    
    // You'll want to consider how to read the information and store it in the
    // struct (or your choice of storage). I've given you
    // of information on how the reading process will be: 1 string
    // followed by 5 integers, so how will you implement this?

    inFile.close();
}

int main()
{
    personInformation personInformationObject[20]; // A fixed size. Max of 20 people
                                                   // can be read from the file.
                                                   // If you're not looking for
                                                   // fixed, consider using
                                                   // an STL container.
    readInformationFromFile(personInformationObject);
    return 0;
}
Jun 13, 2018 at 11:21am
Thank you so much , this helped I lot .
we are not supposed to use different functions yet . we haven't studied it .
I have started the code and its outputting the way I want to . Im supposed to calculate the the total of all of those numbers and the average . which Im kinda struggling with at the moment .


this is how far I am at the moment.


#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;

int main() {

ifstream intputFile;
intputFile.open("input.txt");

cout << "enter number of months ";
int NumberOfmonths;
cin >> NumberOfmonths;


cout <<fixed<<showpoint<<setprecision(2);



string Name;
double rent1,rent2,rent3,rent4,rent5;

while (intputFile>>Name>>rent1>>rent2>>rent3>>rent4>>rent5) {
cout <<Name<<"\t"<<rent1<<"\t"<<rent2<<"\t"<<rent3<<"\t"<<rent4<<"\t"<<rent5<<endl;



cout <<" ";

}

if ((rent1==0)||(rent2==0)||(rent3==0)||(rent4==0)||(rent5==0))
cout << " one of the complexes submited zero";

double rentTotal = (rent1+rent2+rent3+rent4+rent5);
double rentAvarge = rentTotal/NumberOfmonths;
cout << "the total is "<<rentTotal;
cout << " the average is "<< rentAvarge;





































return 0;
}
Jun 13, 2018 at 12:54pm
Please use code tags when posting code. See http://www.cplusplus.com/articles/jEywvCM9/
You can edit your posts to add the tags.

we are not supposed to use FOO yet . we haven't studied FOO

This always cracks me up. While I understand the rationale, I don't approve it.


1
2
double rentTotal = (rent1+rent2+rent3+rent4+rent5);
double rentAvarge = rentTotal / NumberOfmonths;

What is average? Is it a sum of values divided by the count of those values?

You compute the sum of 5 values (rent{1..5}).
You divide that sum with NumberOfmonths.
If NumberOfmonths equals 5, then the result is average of the five values, is it not?


The details are very important in programming.
Jun 13, 2018 at 2:51pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;

int main() {

    ifstream intputFile;
    intputFile.open("./info.dat");

    cout << "enter number of months ";
    int NumberOfmonths;
    cin >> NumberOfmonths;


    cout <<fixed<<showpoint<<setprecision(2);



    string Name;
    double rent1,rent2,rent3,rent4,rent5;

    while (intputFile>>Name>>rent1>>rent2>>rent3>>rent4>>rent5) {
        cout <<Name<<"\t"<<rent1<<"\t"<<rent2<<"\t"<<rent3<<"\t"<<rent4<<"\t"<<rent5<<endl;
        cout <<" ";
    }

    if ((rent1==0)||(rent2==0)||(rent3==0)||(rent4==0)||(rent5==0)) 
        cout << " one of the complexes submited zero\n";

    double rentTotal = (rent1+rent2+rent3+rent4+rent5);         // This is just King's rent.
                                                                // After you
                                                                // have read in
                                                                // Main and
                                                                // Clay's data,
                                                                // you replaced
                                                                // it with
                                                                // King's data.
                                                                // In other
                                                                // words, you
                                                                // never
                                                                // actually do
                                                                // use data from
                                                                // Main and from
                                                                // Clay, which is
                                                                // probably something
                                                                // you don't want to do.
    double rentAvarge = rentTotal/NumberOfmonths;
    cout << "the total is " << rentTotal << endl;
    cout << " the average is " << rentAvarge << endl << endl;

}


Honestly, it's quite silly that you are being asked to design such a program without using user defined functions...
Jun 13, 2018 at 4:07pm
ok I understand now . but how can I calculate a total for all of the values and average as well ? in the same time he asking me to calculate the highest income complex which I have no Idea how .
I emailed the instructor asking hime few things ,but there is no response yet.

Thank you again this very helpful so far.
Jun 13, 2018 at 5:00pm
Store the totals for each person in an array. From there, you can calculate the total by adding up each element in the array and the average by diving the total by the number of persons.
Jun 13, 2018 at 10:09pm
I have tried that and didn't work gave me non sense total


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;

int main() {

    ifstream intputFile;
    intputFile.open("input.txt");
    
    cout << "enter number of months ";
    int NumberOfmonths;
    cin >> NumberOfmonths;
    
    
  cout <<fixed<<showpoint<<setprecision(2);
    
  
    
    string Name;
    double rent1,rent2,rent3,rent4,rent5;
    double rentAvarge;
    double rentTotal=0.0;
    
    while (intputFile>>Name>>rent1>>rent2>>rent3>>rent4>>rent5) {
        cout <<Name<<"\t"<<rent1<<"\t"<<rent2<<"\t"<<rent3<<"\t"<<rent4<<"\t"<<rent5<<endl;
        
    
  
        cout <<" ";
        double  ArryMain[5]={rent1,rent2,rent3,rent4,rent5};
        
        for (int i =1; i <=5;i++){
            rentTotal +=ArryMain[i];
            rentAvarge=rentTotal/NumberOfmonths;
            
           
        }
        
    }
    if ((rent1==0)||(rent2==0)||(rent3==0)||(rent4==0)||(rent5==0)){
        cout << " one of the complexes submited zero";
    }

   
    
    cout << "the total is "<<rentTotal;
    cout << " the average is "<< rentAvarge;
   
    
        
    
        
    
    

        
  
      
  

    
        
    
    
    
    
    
    
    

        

    
    
    
    
    return 0;
}

Jun 14, 2018 at 2:08am
double ArryMain[5]={rent1,rent2,rent3,rent4,rent5};

for (int i =1; i <=5;i++){
rentTotal +=ArryMain[i];

this is wrong.
in c++ arrays are from 0 to size-1.
so you wanted

for(int i = 0; i < 5; i++) //0th, 1st, 2, 3, 4 is 5 total items...




Jun 14, 2018 at 3:34pm
If I do that it will only calculate the last complex total rather than the whole thing
Jun 14, 2018 at 4:08pm
Then your logic, design, or something else is wrong. This is just pure c++ language stuff:

double ArryMain[5]

and

for (int i =1; i <=5;i++){
rentTotal +=ArryMain[i];

is accessing location 5 which is invalid.

if you need a 6th location, you need to define it with
double ArryMain[6]

Jun 15, 2018 at 11:29am
Given input:
Main 2000 1000 3000 2000 2000
Clay 3000 5000 4000 5000 4000
King 2000 2000 4000 2000 0

* What is a "Company"? Is it all input or just one line?
* What is a "Complex"? A line?
* What is "monthly income"? Given "if any of the months had zero income", probably one value.

What is in a line then?
Is it one string, "name of Complex", and then N integers that are monthly income?
The N is then number of months.
The example happens to have data for 5 months (for each Complex). You cannot assume in your code that the N is 5.


If you cannot know how much data is coming during this run of the program, then you should either allocate space for data dynamically, or process each value as it comes in, without storing the value. In this case the latter should be feasible.



PS. Please reduce the amount of empty lines.
Topic archived. No new replies allowed.