# Can someone Dumb this down for me?

Page 1 of 1

## 6 Replies - 4228 Views - Last Post: 02 February 2010 - 11:53 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=153319&amp;s=eb7d0be3b6d12745e0a5d698180764ac&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 asharp03

• New D.I.C Head

Reputation: 0
• Posts: 40
• Joined: 27-April 09

# Can someone Dumb this down for me?

Posted 01 February 2010 - 02:17 PM

Ok all here is the question straight from the book.
Suppose that the file inData.txt contains the following data:
10.20 5.35
15.6
Randy Gill 31
18500 3.5
A

The numbers in the first line represent the length and width, respectively, of a rectangle. The number in the second line represents the radius of a circle. The third line contains the first name, last name, and the age of a person. The first number in the fourth line is the savings account balance at the beginning of the month and the second number is the interest rate per year. (Assume pi=3.1416) The fifth line contains an uppercase letter between A and Y(inclusive). Write statements so that after the program executes, the contents of the file outData.txt are as shown below. If neccessary declare additional variable. Your statements should be general enough so that if the content of the infput file changes and the program is run again(without editing and recompiling), it outputs the appropriate results.

Rectangle:
Length= 10.20, width= 5.35, area= 54.57, parameter = 31.10

Circle:
Radius =15.60, area=764.54, circumference = 98.02

Name: Randy Gill age:31
Beginning balance = \$18500.00, interest rate = 3.50
Balance at the end of the month = 18553.96

The characeter that comes after A in the ASCII set is B

Now after reading this more the once and even typing it here, I have no clue as to what the heck I should be doing. The step before this one asked me to open both the inData.txt file and the outData.txt file which I did using this code.
```inFile.open("inData.txt");
outFile.open("outData.txt");

```

Can someone please put this into simpler terms for me, in other words please dumb it down for me.

This post has been edited by asharp03: 01 February 2010 - 02:18 PM

Is This A Good Question/Topic? 0

## Replies To: Can someone Dumb this down for me?

### #2 xTorvos

• D.I.C Regular

Reputation: 61
• Posts: 271
• Joined: 23-October 09

## Re: Can someone Dumb this down for me?

Posted 01 February 2010 - 02:23 PM

Basically, all the information you gave us will be in a text file. You need to read in the text file and be able to assign each of those integers, floats, strings, and characters to variables. Then you need to output the data to another file in the format that they gave you.

It would help if you let us know specific parts of the problem that you don't understand so that we can try to break it down and help you with the individual parts.

### #3 GenHornet18

• Darken the Radar

Reputation: 36
• Posts: 629
• Joined: 19-October 09

## Re: Can someone Dumb this down for me?

Posted 01 February 2010 - 02:23 PM

Your assignment asks simply read in a file, process the information contained within and output it in the corresponding format that you have given. This is basically a formatting question. Start by first reading in the file and using the information it has inside (you don't need a lot of variables as you can output as you read the file down).

### #4 asharp03

• New D.I.C Head

Reputation: 0
• Posts: 40
• Joined: 27-April 09

## Re: Can someone Dumb this down for me?

Posted 01 February 2010 - 02:32 PM

xTorvos, on 1 Feb, 2010 - 01:23 PM, said:

Basically, all the information you gave us will be in a text file. You need to read in the text file and be able to assign each of those integers, floats, strings, and characters to variables. Then you need to output the data to another file in the format that they gave you.

It would help if you let us know specific parts of the problem that you don't understand so that we can try to break it down and help you with the individual parts.

Write statements so that after the program executes, the contents of the file outData.txt are as shown below.

This is where I am confused. Are they just wanting me to lable what each of the numbers on each line represent and then find the parameter, circumfrence and end of the month balance.

### #5 Bench

• D.I.C Lover

Reputation: 944
• Posts: 2,464
• Joined: 20-August 07

## Re: Can someone Dumb this down for me?

Posted 02 February 2010 - 03:36 AM

asharp03, on 01 February 2010 - 09:32 PM, said:

This is where I am confused. Are they just wanting me to lable what each of the numbers on each line represent and then find the parameter, circumfrence and end of the month balance.

The best person to ask that to would be whoever provided you with the original specification. Its possible (even likely) that you have been deliberately provided with slightly ambiguous requirements because you are expected to be able to derive specific questions and ask them as part of your analysis of the problem. In real-world development, this happens on every project - you will never, ever be given a complete comprehensive specification for a solution which doesn't have some ambiguities hanging over it.

### #6 asharp03

• New D.I.C Head

Reputation: 0
• Posts: 40
• Joined: 27-April 09

## Re: Can someone Dumb this down for me?

Posted 02 February 2010 - 06:32 AM

Bench, on 02 February 2010 - 02:36 AM, said:

asharp03, on 01 February 2010 - 09:32 PM, said:

This is where I am confused. Are they just wanting me to lable what each of the numbers on each line represent and then find the parameter, circumfrence and end of the month balance.

The best person to ask that to would be whoever provided you with the original specification. Its possible (even likely) that you have been deliberately provided with slightly ambiguous requirements because you are expected to be able to derive specific questions and ask them as part of your analysis of the problem. In real-world development, this happens on every project - you will never, ever be given a complete comprehensive specification for a solution which doesn't have some ambiguities hanging over it.

The book asked us to do this. The professor just told us to do programming assignment 1 and 2 and this is part of programming assignment 1. So really no one provided us with the specification other then the textbook telling us to do it.

### #7 David W

• DIC supporter

Reputation: 298
• Posts: 1,839
• Joined: 20-September 08

## Re: Can someone Dumb this down for me?

Posted 02 February 2010 - 11:53 AM

GenHornet18, on 01 February 2010 - 01:23 PM, said:

Your assignment asks simply read in a file, process the information contained within and output it in the corresponding format that you have given. This is basically a formatting question. Start by first reading in the file and using the information it has inside (you don't need a lot of variables as you can output as you read the file down).

This was very good advice by 'GenHornet18'... but since you still seem a little lost ...

this example may help you get started programming in C++ ...

Note: the first thing is to clearly understand the task at hand ... and then to resolve the issues one by one ... until done.

```// reformat_inData.txt.cpp

// http://developers-heaven.net/forum/index.php/topic,46.0.html

// NOTE: need file inData.txt in same folder as running executable file ...

// file: inData.txt contains the following data:
/*
10.20 5.35
15.6
Randy Gill 31
18500 3.5
A
*/

// will be reformatted so that the ... (Note: EXACT output as given, spaces, spelling)

// file: outData.txt is ...
/*
Rectangle:
Length= 10.20, width= 5.35, area= 54.57, parameter = 31.10

Circle:
Radius =15.60, area=764.54, circumference = 98.02

Name: Randy Gill age:31
Beginning balance = \$18500.00, interest rate = 3.50
Balance at the end of the month = 18553.96

The characeter that comes after A in the ASCII set is B
*/

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <cstdlib>

using namespace std;

const double PI = 3.1416;

int main()
{
// open file to read ...
ifstream fin( "inData.txt" );

// open file to write ...
ofstream fout( "outData.txt" );

// now read in data, item by item ...
// and then output the reformatted data ...

// set precision
fout << setprecision(2) << fixed;

float length, width;
fin >> length >> width;
fout << "Rectangle:\n"
<< "Length= " << length << ", width= " << width
<< ", area= " << length*width << ", parameter = " << (length+width)*2
<< endl << endl;

fout << "Circle:\n"
<< ", circumference = " << PI*2*radius
<< endl << endl;

string firstName, lastName;
int age;
fin >> firstName >> lastName >> age;
fout << "Name: " << firstName << " " << lastName << " age:" << age
<< endl;

double bal, iRate;
fin >> bal >> iRate;
fout << "Beginning balance = \$" << bal << ", interest rate = " << iRate
<< "\nBalance at the end of the month = " << bal*(1+iRate/12)
<< endl << endl;

char capLet;
fin >> capLet;
fout << "The characeter that comes after " << capLet
<< " in the ASCII set is " << char( capLet+1 ) << endl;

fout.close();
fin.close();

// and ... if using Windows, can now ...
system( "notepad outData.txt" ); // and see the newly formatted output ...
}

```

This post has been edited by David W: 02 February 2010 - 12:04 PM