Homework HELP!!urgent!!

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2008
Posts: 2
Reputation: sds234 is an unknown quantity at this point 
Solved Threads: 0
sds234 sds234 is offline Offline
Newbie Poster

Homework HELP!!urgent!!

 
0
  #1
Nov 5th, 2008
I have no idea ho to write a program for this problem and i am new to C++ so I really needhelp!!

Consider the following file called "raw_points.txt". The first line of this file contains a count of how many pairs of coordinates are specified in this file. The remaining lines contain pairs of (x,y) coordinates, one pair per line and separated by a space:

raw_points.txt

15
0 1.38
87 0
32 32
3.2 6.4
1.25252 0.680254
1.6877 0.137556
0.819814 1.75999
0.638961 1.96114
0.17001 1.81526
0.205019 1.84396
1.0151 1.74458
0.666519 1.38482
1.11389 0.72383
0.0639877 1.71702
0.197969 1.75414


If you calculate the radial length of each coordinate pair using the Pythagorean Theorem you get lengths ranging anywhere from 1.33 to 87. Let's normalize the numbers so that the radial length is always exactly 1.0.
As a rationale, imagine that we're wanting to convert the numbers into a table of cosine and sine values of the angle represented by each coordinate pair. This is useful in many situations - for example, many video games and computer graphics applications need "normal maps" that indicate the angle that each pixel on an image is "facing" - when lighting calculations are applied, this makes a flat picture of a rock surface look 3D due to the resulting highlights and shadows.

The formula to take a raw coordinate pair (x,y) and normalize it as (x',y') is simple:

x' = x / r
y' = y / r

where r is the radial length of (x,y) - which itself is:

r = sqrt( x2 + y2 )

Here's the same data but with normalized coordinate pairs:


normalized_points.txt

15
0 1
1 0
0.707107 0.707107
0.447214 0.894427
...
0.112146 0.993692


Notice how the numbers are still proportionally the same relative to one another - the polar direction stays the same but the polar distance becomes 1.0.



Assignment
Make a proj8 directory. Use Vim to create the file "raw_points.txt" - copy the raw_points.txt contents from above, start editing a file by the same name, go into insert mode, and type SHIFT+INSERT to paste the numbers in.
Next, write a program to load the data from raw_points.txt, convert it, and save it as normalized_points.txt. Here are some guidelines.

Appendix A at the end of this assignment lists some relevant file commands you'll need.

Open the file "raw_points.txt" as an input filestream.

Open the file "normalized_points.txt" as an output filestream.

Read in the count of how many points there are from the input file.

Write the count out to the output file (with an endl) and then repeat the following that many times:
Read in an x value.

Read in a y value.

Calculate the radial length of (x,y).

Divide both x and y by r.

Write x and y to the output file, separated by a space and with a cursor return at the end.


Close both the input and the output file.
Compile and run the program. Nothing should print to the screen - if it does, you're accidentally printing to the screen instead of to the output file. If you type "cat normalized_points.txt" you should see the same numbers as shown in the example above.



Also have your program work with command line arguments instead of "hard-coding" the filenames in. You should be able to type:
./proj8 raw_points.txt normalized_points.txt

and have the program figure out what two filenames you typed as you ran the program. Note that the specific filenames "raw_points.txt" etc. should no longer be present in your source code.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: Homework HELP!!urgent!!

 
0
  #2
Nov 5th, 2008
Well, and what's your problem?
May be better start from two wonderful ballades on this forum rules?..
http://www.daniweb.com/forums/thread78223.html
http://www.daniweb.com/forums/announcement118-2.html
Last edited by ArkM; Nov 5th, 2008 at 5:37 am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 2
Reputation: sds234 is an unknown quantity at this point 
Solved Threads: 0
sds234 sds234 is offline Offline
Newbie Poster

Re: Homework HELP!!urgent!!

 
0
  #3
Nov 5th, 2008
What I need to know is do i have to open both the files in the program and what conditions i have to use in the while loop.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 182
Reputation: mrboolf will become famous soon enough mrboolf will become famous soon enough 
Solved Threads: 18
mrboolf mrboolf is offline Offline
Junior Poster

Re: Homework HELP!!urgent!!

 
0
  #4
Nov 5th, 2008
Open the file "raw_points.txt" as an input filestream.

Open the file "normalized_points.txt" as an output filestream.

Read in the count of how many points there are from the input file.

Write the count out to the output file (with an endl) and then repeat the following that many times
1) Yes you do
2) start from i=0 and loop while i<count, incrementing i at every passage
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: Homework HELP!!urgent!!

 
0
  #5
Nov 5th, 2008
Answer#1: Look at the assignment. Of course, you must open file before use (read or/and write) it. There are two files in your assignment...

Answer#2 - counter-question: where is that while loop? No loop - no condition...

Apropos (about the original post): in my opinion, no ideas - no problems...
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Homework HELP!!urgent!!

 
0
  #6
Nov 5th, 2008
I still see no code from the OP.

Code would be a nice start.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 1
Reputation: Endersama is an unknown quantity at this point 
Solved Threads: 0
Endersama Endersama is offline Offline
Newbie Poster

Re: Homework HELP!!urgent!!

 
0
  #7
Nov 24th, 2008
lol, this person must be in my class. I hate to sound like an *******, and honestly the reason i found this forum site was looking up code for this exact assignment, but the instructions that were given to us actually give us the code for what is being asked here.

but im a nice person, so here is what i have for you. sorry if im breaking forum rules here, but this assignment is definitely a pain in the %^&* for the lack of teaching skills.

int main()
{
ifstream infile( "raw_points.txt" );
ofstream outfile( "normalized_points.txt" );
int c=0;
double n;
string line;

while(!infile.eof()) {
getline (infile, line);
c++;
}
outfile<< c<< " lines"<< endl;

for (x = 0; x<= c; x++)
{

}




That will read in the number of lines from the file and output the number of lines to the output file.

back to trying to find out what exactly this normalize bit means.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 397
Reputation: StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light 
Solved Threads: 72
StuXYZ StuXYZ is offline Offline
Posting Whiz

Re: Homework HELP!!urgent!!

 
0
  #8
Nov 25th, 2008
This just doesn't work, your read the file into line one line at a time
and each time overwrite the previous line before actually doing anything.

Move the } below c++; down one line but still it doesn't do much.
(other than actually print
1 lines
2 lines ....


Normalize means divide a vector by a number such that the length of the vector is 1.0. A vector with length 1 is called a unit vector.
It is applicable to all dimensionality, e.g. vector(3/4,-1/4,\sqrt{6}/4) is a unit vector.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC