{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# COS120 hw1 - denominator divided by space\n" cin>>...

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

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

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: denominator divided by space \n"; cin >> nom1 >> den1 >> nom2 >> den2; sum = (float)(nom1+nom2)/(den1+den2); // casting from int to float cout << "The sum is:\n"; cout << nom1 << "/" << den1 << "+" << nom2 << "/" << den2 << "=" << nom1+nom2 << "/" << den1+den2 << "or" << 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 <iostream> using namespace std; int main (void) { int number_of_sec, hours, minutes, seconds; cout << "Enter a number between 0 and 21,600\n"; cin >> number_of_sec; hours = number_of_sec/3600; minutes = (number_of_sec%3600)/60; seconds = (number_of_sec%3600)%60; cout << "The number of seconds entered is equivalent to:\n"; cout << hours << " hours " << minutes << " minutes and " << seconds << " seconds"; return 0; }...
View Full Document

{[ snackBarMessage ]}

### Page1 / 2

COS120 hw1 - denominator divided by space\n" cin>>...

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

View Full Document
Ask a homework question - tutors are online