View Single Post
  #4  
Old 17-09-2008, 07:32 PM
BSIT07-01's Avatar
BSIT07-01 BSIT07-01 is offline
Addicted to Computer


 
Join Date: Sep 2007
Location: ------------
Age: 34
Posts: 1,309
Contact Number: ---------------
Program / Discipline: BSIT
Class Roll Number: 07-01
BSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant future
Default Re: Solution of Ex 5,6,2 & 4 Ch# 5 Robert Lafore OOP c++

Exercise # 4
(: A different Approach


Code:
#include <iostream>
using namespace std;

int count=1;
struct dist
    {
    int feet;
    int inches;
    };

dist largedist(dist, dist);
dist correctdist(dist);
void display(dist);
    
void main()
{
    dist a,b,larger;
    cout<<"\nEnter Feet of First Distace: ";
    cin>>a.feet;
    cout<<"\nEnter Inches of First Distace: ";
    cin>>a.inches;
    cout<<"\nEnter Feet of 2nd Distace: ";
    cin>>b.feet;
    cout<<"\nEnter Inches of 2nd Distace: ";
    cin>>b.inches;
    if (a.inches>=12)
        a=correctdist(a);
    if(b.inches>=12)
        b=correctdist(b);


    larger=largedist(a,b);

    cout<<"\nLarger distace = ";
    display(larger);

    
    
}



dist largedist(dist a, dist b)
{
    dist large={12,3};
    if(a.feet>b.feet)
        large=a;
    else if (a.feet<b.feet)
        large=b;
    else if(a.feet==b.feet)
    {
        if(a.inches>b.inches)
            large= a;
        else if(a.inches<b.inches)
            large = b;
        
    }

return large;
}

dist correctdist(dist a)
{
    dist correct;
    correct.feet=a.feet+a.inches/12;
    correct.inches=a.inches%12;
    
    
    cout<<"\nNote: The Distance Value "<<a.feet<<"\""<<a.inches<<"\' is corrected to "<<correct.feet<<"\""<<correct.inches<<"\'\n";



return correct;
}


void display(dist a)

{
cout<<a.feet<<"\""<<a.inches<<"\'";


}

Reply With Quote