Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Need help in C++ homework... sorry

Name: Anonymous 2007-02-10 15:55

It is a more of a logic problem then programming and I am having a hard time dealing with it last nigh

"Angles are often measured in degrees (), minutes (‘), and seconds (“). There are 360 degrees in a circle, 60 minutes in one degree, and 60 seconds in one minute. Write a program that reads two angles expressed in degrees, minutes, and seconds from a file, and then calculates and prints their sum. The number of minutes in your answer should be no greater than 59, and the number of seconds in your answer should be no greater than 59. Why do you suppose that’s the case?

this is what in the input file:
3358 14 55
5 24 55

my codes so far
#include <iostream>  // for the cout D M S
#include<fstream>   // needed for openinga file
#include<string>

using namespace std;



main()
{
     
ifstream infile ;
double D1,M1,S1,D2,S2,M2 ;
int t,D,S,M;

infile.open("C:\\Lab4InputFile.txt");

infile >> D1 >> M1 >> S1 >> D2 >> M2 >> S2;


t= ((D1*360*60)+(M1*60)+S1) + ((D2*360*60)+(M2*60)+S2);

cout <<"\n t"<<t<<"\n";

D = t/60/360;             // my main problem is here here
M = t%3600/60;
S = t/3600/60/6;



cout << D1 << "d " << M1 << "m " << S1 << "s " << "+ " << D2 << "d " << M2 << "m " << S2 << "s " ;

cout <<"= "<< D << "d "<< M <<"m "<< S <<"s "  ;

infile.close() ;
cout<< "Done \n";
system("PAUSE");
return 0;
}

thanx

Name: Anonymous 2007-02-10 16:42

One word, the abscence of indentation of code. Thread over.

Name: Anonymous 2007-02-10 16:45

I would help you but i don't get it :S
What are you supposed to do with those numbers:

3358 14 55
5 24 55

And finally what the output of the program should be?

Name: Anonymous 2007-02-10 16:59

Ok sorry I didn't copy paste the hint and ouput

"Hint: This problem can be messy, unless you tackle it in a methodical way. A suggested approach is to first convert both angles to seconds, before you add them. After you do the addition, your result will be in seconds. You can then convert the resulting seconds to degrees, minutes, and seconds, and display your answer in that form.
Since it may be difficult to print the special character representing degrees, use the characters d, m, and s to represent degrees, minutes, and seconds, respectively. For example, 15034’21” can be represented as 150d 34m 21s. Your answer should be presented in the following format:

                     7d 14m 55s + 5d 24m 55s = 12d 39m 50s

You may obtain a sample input file from Blackboard.  Test your program with various pairs of angles (i.e., multiple input files)."

the input file is a .txt file with the 6 values in it. I am not having a problem with oppining the file it is just the part where I have to convert all seconds to degrees and minutes. I rewrited the cpp so you wouldn't need to make a .txt file

#include <iostream>  // for the cout D M S
#include<string>

using namespace std;

main()
{
     

double D1 =3358,M1=14,S1=55,D2=5,S2=24,M2=55 ;
int t,D,S,M;



t= ((D1*360*60)+(M1*60)+S1) + ((D2*360*60)+(M2*60)+S2);

cout <<"\n t"<<t<<"\n";

D = t/60/360;             // my main problem is here
M = t%3600/60;            //I can't get to turn everything back
S = t/3600/60/6;          //to DMS

cout << D1 << "d " << M1 << "m " << S1 << "s " << "+ " << D2 << "d " << M2 << "m " << S2 << "s " ;
cout <<"= "<< D << "d "<< M <<"m "<< S <<"s "  ;
cout<< "Done \n";
system("PAUSE");
return 0;
}


//Simply all what I want to do is to change the 2 values to seconds, add them then converting them back to DMS.

Name: Anonymous 2007-02-10 17:03

Something along these lines:

// first convert everything to a common measure (seconds)
ang1 = deg1 + 60 * min1 + 3600 * sec1;
ang2 = deg2 + 60 * min2 + 3600 * sec2;

// find the difference
diff = abs(ang1 - ang2);

// convert back to deg, min, sec
finaldeg = (int)(diff / 3600);
remainder = diff % 3600;
finalmin = (int)(remainder / 60);
finalsec = remainder % 60;

Name: Anonymous 2007-02-10 17:05

Correction:

ang1 = sec1 + 60 * min1 + 3600 * deg1;
ang2 = sec2 + 60 * min2 + 3600 * deg2;


Don't forget that 360 degrees is a complete loop, so remove anything in excess of it.

Name: Anonymous 2007-02-10 17:18

it was diff = abs(ang1 + ang2) Thank you that will do it

Name: Anonymous 2007-02-10 20:21

>>6: Don't forget that 360 degrees is a complete loop, so remove anything in excess of it.

This means that you do a check for degrees % 360.
This should result in a sort of feedback loop where you have to re-check your total number of minutes and seconds, probably.

Name: Anonymous 2007-02-10 23:24

Fortunately not. Just do the modulo on degrees alone once you've finished conversions.

finaldeg = finaldeg % 360;

Name: Anonymous 2007-02-10 23:32

>>7
If you're finding the sum, not the difference, you don't need abs().

Name: Anonymous 2007-02-12 3:51

>>9
If you don't mind because the library does it itself or you'll do further processing to it, don't; you can spare your processor of the IDIV.

CFLAGS JUST KICKED IN, YO!

Name: Anonymous 2009-01-14 14:19

Turing

Name: Anonymous 2009-03-06 13:45

The string example pushed.

Name: Anonymous 2012-03-23 23:38

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boyAll work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boyAll work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boyAll work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boyAll work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boyAll work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boyAll work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

Name: Sgt.Kabuꛃkiman晓蛴 2012-05-28 22:23

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy

Name: Anonymous 2013-09-01 13:23


The characters initially were too gimmicky to feel like actual characters, though they're starting to flesh out a little bit now.

Name: Anonymous 2013-09-01 14:54


 Anyone got the chart for latest Nogizaka's handshake event?

Don't change these.
Name: Email:
Entire Thread Thread List