Q BgQuestion:

      
Pupil
Karma Points: 60
Respect (87%):
posted by  Bunny09 on 11/5/2009 1:23:00 AM  |  status: Live  |  Earned Karma: 60

important numbers

Course Textbook Chapter Problem Needs by
Operating Systems Operating Systems (2nd) by Nutt 12 7PE 11/5/2009 at 9:00:00 AM
Question Details:
i= 10, r = 23
Let me know if this helps.. Remember who the head of your life is.. ;-)
Bonus Point Alert! Earn +15 additional karma points for helping this platinum member.

AAnswers:

Answer Question Ask for clarification
Oracle
Karma Points: 31,807
posted by rapunzel on 11/5/2009 6:51:03 AM  |  status: Live
Asker's Rating: Helpful   
Response Details:
please rate - thanks

// program 9
// point value:
// Program that is a fraction calculator

#include <iostream>

using namespace std;
char menu();
void addFractions (int a1, int b1, int a2, int b2, int& num, int& den);
void subtractFractions (int a1, int b1, int a2, int b2, int& num, int& den);
void multiplyFractions ( int a1, int b1, int a2, int b2, int& num, int& den);
void divideFractions ( int a1, int b1, int a2, int b2, int& num, int& den);
int number(string,int&,char);
int main()
{
    int a1, b1, a2, b2, num, den,i;
    string input;
    char ch = menu();
    cout<<"\n\tEnter fraction 1: ";
    cin>>input;
    i=0;
    a1=number(input,i,'/');
    b1=number(input,i,'\0');   
    while (b1==0)
    {     if(b1==0)
             cout<<"\tDenominator can not be zero.\n";
          cout<<"\n\tEnter fraction 1: ";
          cin>>input;
          i=0;
          a1=number(input,i,'/');
          b1=number(input,i,'\0');               
     }
        
      cout<<"\n\tEnter fraction 2: ";
      i=0;
      cin>>input;
      a2=number(input,i,'/');
      b2=number(input,i,'\0');   
       while (b2 ==0)
        {       if (b2==0)
                     cout<< "\tDenominator can not be zero.\n";
                cout<<"\n\tEnter fraction 2: ";
                cin>>input;
                i=0;
                a2=number(input,i,'/');
                b2=number(input,i,'\0');    
         }

        
        switch (ch)
        {
               case '+':
                    addFractions (a1, b1, a2, b2, num, den);
                    cout<< "\n\tThe sum of the fractions is = "
                           << num << "/" << den<<endl;
                    break;
               case '-':
                    subtractFractions (a1, b1, a2, b2, num, den);
                    cout<<"\n\tDifference of the fractions is = "
                           << num << "/" << den<<endl;
                    break;
               case '*':
                    multiplyFractions (a1, b1, a2, b2, num, den);
                    cout <<"\nProduct of the fractions is = "
                           << num << "/" << den<<endl;
                    break;
               case '/':
                    if( a2 !=0)
                    {
                        divideFractions (a1, b1, a2, b2, num, den);
                        cout<< "\nDivision of the fractions = "
                            << num << "/" << den<<endl;
                     }
                     else
                         cout<< "\n\tDenominator fraction "
                             <<"cannot be zero.";
                      break;
        }
               system ("pause");
               return 0;
          }  
          char menu()
          {
               char operationType;
              
               cout<<"\n\n\tProgram that lets the user perform "
                   << "arithmetic operations on fractions.";
                  
               cout<< "\n\n\t\t M E N U";
               cout<< "\n\n\tAddition: +"
                   << "\n\tSubtraction: -"
                   << "\n\tMultiplication: *"
                   << "\n\tDivision: /";
                  
                   cout<<"\n\tEnter operation to perform:  ";
                   cin >> operationType;
                   return operationType;
               }
              void addFractions (int a1, int b1, int a2, int b2, int& num, int& den)
              {
                 if (b1 == b2)
                 {
                            num = (a1 + a2);
                            den = b2;
                 }
                 else
                 {
                            num = ((a1* b2) + (b1 * a2));
                            den = b1 * b2;
                 }                
              }
              void subtractFractions (int a1, int b1, int a2, int b2, int& num, int& den)
              {
                    if (b1==b2)
                 {
                            num = (a1 - a2);
                            den = b2;
                 }
                 else
                 {
                            num = ((a1* b2) - (b1 * a2));
                            den = b1 * b2;
                 }
                 
              }
              void multiplyFractions ( int a1, int b1, int a2, int b2, int& num, int& den)
              {
                   num = a1 * a2;
                   den = b1 * b2;
                   }
              void divideFractions ( int a1, int b1, int a2, int b2, int& num, int& den)
              {
                   num = a1 * b2;
                   den = b1 * a2;
               }
int number(string in,int &index,char c)
{int i,num=0;
char digit;
for(i=index;;i++)
   {digit=in[i];
    if(digit==c)
       {index=i+1;
       return num;
       }
   num=num*10+(digit-48);
   }
}



Note to all members 1. Please 1 question per post 2. Show respect to your fellow members by rating all answers. 3. When rating remember that the first answer is not necessarily the best answer. 4. When answering questions, explain what you are doing, so that the asker will learn, don't just give a meaningless number. 5. Your answers should be your work. Don't copy from another member, this is Karma abuse and possible disciplinary actions against you. and GOOD LUCK to you all!!
Oracle
Karma Points: 31,807
posted by rapunzel on 11/5/2009 7:22:00 PM  |  status: Live
Asker's Rating: Helpful   
Response Details:
please rate - thanks

// program 9
// point value:
// Program that is a fraction calculator

#include <iostream>

using namespace std;
char menu();
void addFractions (int a1, int b1, int a2, int b2, int& num, int& den);
void subtractFractions (int a1, int b1, int a2, int b2, int& num, int& den);
void multiplyFractions ( int a1, int b1, int a2, int b2, int& num, int& den);
void divideFractions ( int a1, int b1, int a2, int b2, int& num, int& den);
int number(string,int&,char);
int main()
{
    int a1, b1, a2, b2, num, den,i,good=1;
    string input;
    string output="";
    char ch = menu();
    cout<<"\n\tEnter fraction 1: ";
    cin>>input;
    i=0;
    a1=number(input,i,'/');
    b1=number(input,i,'\0');   
    while (b1==0)
    {     if(b1==0)
             cout<<"\tDenominator can not be zero.\n";
          cout<<"\n\tEnter fraction 1: ";
          cin>>input;
          i=0;
          a1=number(input,i,'/');
          b1=number(input,i,'\0');               
     }
      output=input;  
      cout<<"\n\tEnter fraction 2: ";
      i=0;
      cin>>input;
      a2=number(input,i,'/');
      b2=number(input,i,'\0');   
       while (b2 ==0)
        {       if (b2==0)
                     cout<< "\tDenominator can not be zero.\n";
                cout<<"\n\tEnter fraction 2: ";
                cin>>input;
                i=0;
                a2=number(input,i,'/');
                b2=number(input,i,'\0');    
         }
         output=output+" "+ch+" "+input+" = ";
         
        
        switch (ch)
        {
               case '+':
                    addFractions (a1, b1, a2, b2, num, den);
                    break;
               case '-':
                    subtractFractions (a1, b1, a2, b2, num, den);
                    break;
               case '*':
                    multiplyFractions (a1, b1, a2, b2, num, den);
                    break;
               case '/':
                    if( a2 !=0)
                    {
                        divideFractions (a1, b1, a2, b2, num, den);
                        
                     }
                     else
                         {cout<< "\n\tDenominator fraction "
                             <<"cannot be zero.";
                         good=0;
                         }
                      break;
        }
               if(good==1)
                    cout<<"\n          "<<output<<num<<"/"<<den<<endl;
               else
                    cout<<"\n          "<<output<<"undefined"<<endl;
               
               system ("pause");
               return 0;
          }  
          char menu()
          {
               char operationType;
              
               cout<<"\n\n\tProgram that lets the user perform "
                   << "arithmetic operations on fractions.";
                  
               cout<< "\n\n\t\t M E N U";
               cout<< "\n\n\tAddition: +"
                   << "\n\tSubtraction: -"
                   << "\n\tMultiplication: *"
                   << "\n\tDivision: /";
                  
                   cout<<"\n\tEnter operation to perform:  ";
                   cin >> operationType;
                   return operationType;
               }
              void addFractions (int a1, int b1, int a2, int b2, int& num, int& den)
              {
                 if (b1 == b2)
                 {
                            num = (a1 + a2);
                            den = b2;
                 }
                 else
                 {
                            num = ((a1* b2) + (b1 * a2));
                            den = b1 * b2;
                 }                
              }
              void subtractFractions (int a1, int b1, int a2, int b2, int& num, int& den)
              {
                    if (b1==b2)
                 {
                            num = (a1 - a2);
                            den = b2;
                 }
                 else
                 {
                            num = ((a1* b2) - (b1 * a2));
                            den = b1 * b2;
                 }
                 
              }
              void multiplyFractions ( int a1, int b1, int a2, int b2, int& num, int& den)
              {
                   num = a1 * a2;
                   den = b1 * b2;
                   }
              void divideFractions ( int a1, int b1, int a2, int b2, int& num, int& den)
              {
                   num = a1 * b2;
                   den = b1 * a2;
               }
int number(string in,int &index,char c)
{int i,num=0;
char digit;
for(i=index;;i++)
   {digit=in[i];
    if(digit==c)
       {index=i+1;
       return num;
       }
   num=num*10+(digit-48);
   }
}



with answer reduced

// program 9
// point value:
// Program that is a fraction calculator

#include <iostream>

using namespace std;
char menu();
void addFractions (int a1, int b1, int a2, int b2, int& num, int& den);
void subtractFractions (int a1, int b1, int a2, int b2, int& num, int& den);
void multiplyFractions ( int a1, int b1, int a2, int b2, int& num, int& den);
void divideFractions ( int a1, int b1, int a2, int b2, int& num, int& den);
int gcd(int,int);
int number(string,int&,char);
int main()
{
    int a1, b1, a2, b2, num, den,i,good=1,factor;
    string input;
    string output="";
    char ch = menu();
    cout<<"\n\tEnter fraction 1: ";
    cin>>input;
    i=0;
    a1=number(input,i,'/');
    b1=number(input,i,'\0');   
    while (b1==0)
    {     if(b1==0)
             cout<<"\tDenominator can not be zero.\n";
          cout<<"\n\tEnter fraction 1: ";
          cin>>input;
          i=0;
          a1=number(input,i,'/');
          b1=number(input,i,'\0');               
     }
      output=input;  
      cout<<"\n\tEnter fraction 2: ";
      i=0;
      cin>>input;
      a2=number(input,i,'/');
      b2=number(input,i,'\0');   
       while (b2 ==0)
        {       if (b2==0)
                     cout<< "\tDenominator can not be zero.\n";
                cout<<"\n\tEnter fraction 2: ";
                cin>>input;
                i=0;
                a2=number(input,i,'/');
                b2=number(input,i,'\0');    
         }
         output=output+" "+ch+" "+input+" = ";
         
        
        switch (ch)
        {
               case '+':
                    addFractions (a1, b1, a2, b2, num, den);
                    break;
               case '-':
                    subtractFractions (a1, b1, a2, b2, num, den);
                    break;
               case '*':
                    multiplyFractions (a1, b1, a2, b2, num, den);
                    break;
               case '/':
                    if( a2 !=0)
                    {
                        divideFractions (a1, b1, a2, b2, num, den);
                        
                     }
                     else
                         {cout<< "\n\tDenominator fraction "
                             <<"cannot be zero.";
                         good=0;
                         }
                      break;
        }
               if(good==1)
                    {factor=gcd(num,den);
                    num/=factor;
                    den/=factor;
                    cout<<"\n          "<<output<<num<<"/"<<den<<endl;
                    }
               else
                    cout<<"\n          "<<output<<"undefined"<<endl;
               
               system ("pause");
               return 0;
          }  
          char menu()
          {
               char operationType;
              
               cout<<"\n\n\tProgram that lets the user perform "
                   << "arithmetic operations on fractions.";
                  
               cout<< "\n\n\t\t M E N U";
               cout<< "\n\n\tAddition: +"
                   << "\n\tSubtraction: -"
                   << "\n\tMultiplication: *"
                   << "\n\tDivision: /";
                  
                   cout<<"\n\tEnter operation to perform:  ";
                   cin >> operationType;
                   return operationType;
               }
              void addFractions (int a1, int b1, int a2, int b2, int& num, int& den)
              {
                 if (b1 == b2)
                 {
                            num = (a1 + a2);
                            den = b2;
                 }
                 else
                 {
                            num = ((a1* b2) + (b1 * a2));
                            den = b1 * b2;
                 }                
              }
              void subtractFractions (int a1, int b1, int a2, int b2, int& num, int& den)
              {
                    if (b1==b2)
                 {
                            num = (a1 - a2);
                            den = b2;
                 }
                 else
                 {
                            num = ((a1* b2) - (b1 * a2));
                            den = b1 * b2;
                 }
                 
              }
              void multiplyFractions ( int a1, int b1, int a2, int b2, int& num, int& den)
              {
                   num = a1 * a2;
                   den = b1 * b2;
                   }
              void divideFractions ( int a1, int b1, int a2, int b2, int& num, int& den)
              {
                   num = a1 * b2;
                   den = b1 * a2;
               }
int number(string in,int &index,char c)
{int i,num=0;
char digit;
for(i=index;;i++)
   {digit=in[i];
    if(digit==c)
       {index=i+1;
       return num;
       }
   num=num*10+(digit-48);
   }
}
int gcd(int a, int b)     //Euclids algorithm
{while(a!=b)
   {if(a>b)
      a -= b;
    else
      b -= a;
   }
return a;
}        



Note to all members 1. Please 1 question per post 2. Show respect to your fellow members by rating all answers. 3. When rating remember that the first answer is not necessarily the best answer. 4. When answering questions, explain what you are doing, so that the asker will learn, don't just give a meaningless number. 5. Your answers should be your work. Don't copy from another member, this is Karma abuse and possible disciplinary actions against you. and GOOD LUCK to you all!!
Answer Question Ask for clarificarion

Join Cramster's Community

Cramster.com brings together students, educators and subject enthusiasts in an online study community. With around-the-clock expert help and a community of over 100,000 knowledgeable members, you can find the help you need, whenever you need it. Join for free today » How Cramster is different from tutoring »