Sign In
Educators
Flashcards
Study Tools
Good to have you back!
If you've signed in to StudyBlue with Facebook in the past, please do that again.
StudyBlue
Wisconsin
University of Wisconsin - Eau Claire
Computer Science
Computer Science 163
Ernst
C++ Programming- Divide and Multiply Fractions
C++ Programming- Divide and Multiply Fractions
Computer Science 163
with
Ernst
at
University of Wisconsin - Eau Claire
†
† The material on this site is created by StudyBlue users. StudyBlue is not affiliated with, sponsored by or endorsed by the academic institution or instructor.
Get started today
for
free
Taylor J.
Created:
2009-04-30
Last Modified:
2009-04-30
File Size:
2
Views:
14
Related Textbooks:
Problem Solving with C++ (6th Edition)
#include
#include
using namespace std; struct fraction // the structure { int num; int denom; bool positive; }; void multiply_frac (fraction *f1, fraction *f2, fraction *f3) // for multiplying { f3->num = f1->num * f2->num; f3->denom = f1->denom * f2->denom; } void div_frac (fraction *f1, fraction *f2, fraction *f3) // for dividing { f3->num = f1->num * f2->denom; f3->denom = f1->denom * f2->num; } int main() { fraction f1; fraction f2; fraction fresult; char tempchar; bool positive1 = true; bool positive2 = true; // you need 2 positives, for fraction 1 and fraction 2 cout << "Input the first numerator." << endl; cin >> f1.num; cout << "Input the first denominator." << endl; cin >> f1.denom; cout << "Is the fraction positive? (Y/N)" << endl; cin >> tempchar; if (tempchar == 'Y') positive1 = true; else { if (tempchar == 'N' ) positive1 = false; else { cout<<" The program will assume the fraction is positive"<
> f2.num; cout << "Input the second denominator." << endl; cin >> f2.denom; cout << "Is the fraction positive? (Y/N)" << endl; cin >> tempchar; if (tempchar == 'Y') positive2 = true; else { if (tempchar == 'N' ) positive2 = false; else { cout<<"You must type Y or N .The program will assume the fraction is positive"<
Advertisement
Advertisement
Want to see the other 2 page(s) in C++ Programming- Divide and Multiply Fractions?
JOIN TODAY FOR FREE!
Join
with
Email
Words From the Students
"The semester I found StudyBlue, I went from a 2.8 to a 3.8, and graduated with honors!"
Jennifer
Colorado School of Mines