COS120 hw1 - denominator divided by space \n";...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
COS120 Software Development Using C++ Student: Homework Nmr 01 Tasks: Write a program that reads and stores the numerators and denominators of two fractions as integer values. For example, if the numbers 1 and 4 are entered for the first fraction, the fraction is ¼. The program should print the sum of the two fractions as a fraction and as a decimal value. For example, ¼ + ½ = 6/8 or 0.75. Write a program that reads a number of seconds between 0 and 21,600 (6 hours) and displays the hours, minutes and seconds equivalent. Problem 1 /* The program takes the fractions from the keyboard * the nominator and denominator of the first are stored in nom1 and den1 respectively * the nominator and denominator of the second are stored in nom2 and den2 respectively * the program displays the sum as a fraction and as a decimal number */ # include <iostream> using namespace std; int main(void) { int nom1,nom2,den1,den2; float sum; cout << "Enter the fractions, first the nominator and then the
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: denominator divided by space \n&quot;; cin &gt;&gt; nom1 &gt;&gt; den1 &gt;&gt; nom2 &gt;&gt; den2; sum = (float)(nom1+nom2)/(den1+den2); // casting from int to float cout &lt;&lt; &quot;The sum is:\n&quot;; cout &lt;&lt; nom1 &lt;&lt; &quot;/&quot; &lt;&lt; den1 &lt;&lt; &quot;+&quot; &lt;&lt; nom2 &lt;&lt; &quot;/&quot; &lt;&lt; den2 &lt;&lt; &quot;=&quot; &lt;&lt; nom1+nom2 &lt;&lt; &quot;/&quot; &lt;&lt; den1+den2 &lt;&lt; &quot;or&quot; &lt;&lt; sum; return 0; } Problem 2 /* The program gets a number between 0 and 21,600 from the keyboard * and displays the number of hours, minutes and seconds */ # include &lt;iostream&gt; using namespace std; int main (void) { int number_of_sec, hours, minutes, seconds; cout &lt;&lt; &quot;Enter a number between 0 and 21,600\n&quot;; cin &gt;&gt; number_of_sec; hours = number_of_sec/3600; minutes = (number_of_sec%3600)/60; seconds = (number_of_sec%3600)%60; cout &lt;&lt; &quot;The number of seconds entered is equivalent to:\n&quot;; cout &lt;&lt; hours &lt;&lt; &quot; hours &quot; &lt;&lt; minutes &lt;&lt; &quot; minutes and &quot; &lt;&lt; seconds &lt;&lt; &quot; seconds&quot;; return 0; }...
View Full Document

This note was uploaded on 04/24/2010 for the course COS 120 taught by Professor Bonev during the Fall '08 term at American University in Bulgaria.

Page1 / 2

COS120 hw1 - denominator divided by space \n&amp;amp;quot;;...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online