Can someone Dumb this down for me?

Not understanding an assignment question.

Page 1 of 1

6 Replies - 1832 Views - Last Post: 02 February 2010 - 11:53 AM Rate Topic: -----

#1 asharp03  Icon User is offline

  • New D.I.C Head

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

Can someone Dumb this down for me?

Post icon  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. :P

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  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 61
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#3 GenHornet18  Icon User is offline

  • Darken the Radar

Reputation: 36
  • View blog
  • 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).
Was This Post Helpful? 0
  • +
  • -

#4 asharp03  Icon User is offline

  • New D.I.C Head

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

Re: Can someone Dumb this down for me?

Posted 01 February 2010 - 02:32 PM

View PostxTorvos, 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.
Was This Post Helpful? 0
  • +
  • -

#5 Bench  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 855
  • View blog
  • Posts: 2,338
  • Joined: 20-August 07

Re: Can someone Dumb this down for me?

Posted 02 February 2010 - 03:36 AM

View Postasharp03, 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.
Was This Post Helpful? 0
  • +
  • -

#6 asharp03  Icon User is offline

  • New D.I.C Head

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

Re: Can someone Dumb this down for me?

Posted 02 February 2010 - 06:32 AM

View PostBench, on 02 February 2010 - 02:36 AM, said:

View Postasharp03, 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.
Was This Post Helpful? 0
  • +
  • -

#7 David W  Icon User is offline

  • DIC supporter
  • member icon

Reputation: 275
  • View blog
  • Posts: 1,778
  • Joined: 20-September 08

Re: Can someone Dumb this down for me?

Posted 02 February 2010 - 11:53 AM

View PostGenHornet18, 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;
         
    float radius;
    fin >> radius;
    fout << "Circle:\n"
         << "Radius =" << radius << ", area=" << PI*radius*radius
         << ", 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

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1