BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan Right Header

HOME BZU Mail Box Online Games Radio and TV Cricket All Albums
Go Back   BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan > Institute of Computing > Bachelor of Science in Information Technology > BsIT 3rd Semester > Object Oriented Programming

Object Oriented Programming By Mam Sidra Malik


Reply
 
Thread Tools Search this Thread Rating: Thread Rating: 6 votes, 4.67 average. Display Modes
  #1  
Old 11-09-2008, 09:06 PM
BSIT07-01's Avatar
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 Solution of Ex 5,6,2 & 4 Ch# 5 Robert Lafore OOP c++


Solution of Exercise 5


Code:
#include <iostream>
using namespace std;


long hms_to_secs(int h,int m,int s)

{
    long seconds;

    seconds=h*3600+m*60+s;
    return seconds;

}

void main()


{

char c;
int h,m,s;
for(int n=1;n<10;n++)
{
cout<<"enter time in this formate 12:12:49  :  ";

cin>>h>>c>>m>>c>>s;

cout<<hms_to_secs(h,m,s)<<endl;
}

}



Solution of Exercise 6


Code:
#include <iostream>
using namespace std;

struct time
{
    int hours,minutes,seconds;

};

long time_to_secs(time);

time secs_to_time(long);

int main()


{
    time time1,time2;
    
    char colon;

    cout<<"enter First time in this format (12:30:30):";
    cin>>time1.hours>>colon>>time1.minutes>>colon>>time1.seconds;

    cout<<"enter Second time in this format (12:30:30):";
    cin>>time2.hours>>colon>>time2.minutes>>colon>>time2.seconds;

    long totalseconds1=time_to_secs(time1);

    long totalseconds2=time_to_secs(time2);

    long totalseconds=totalseconds1+totalseconds2;

    time totaltime=secs_to_time(totalseconds);


    cout<<"\nTotal Time: "<<totaltime.hours<<":"<<totaltime.minutes<<":"<<totaltime.seconds<<endl;

    return 0;

}

long time_to_secs(time time1)

{


long totalseconds=time1.hours*3600 + time1.minutes*60 + time1.seconds;

return totalseconds;
}


time secs_to_time(long totalseconds)

{
    int temp;
    time time3;

    time3.hours=totalseconds/3600;

    temp=totalseconds%3600;

    time3.minutes=temp/60;

    time3.seconds=temp%60;

    return time3;

}


Ahmad ne kaha tha mein kar doon ga post...
Ahmad ne tu post karnay hi nahin hain, Main he kar daita hoon

Reply With Quote
  #2  
Old 11-09-2008, 09:29 PM
BSIT07-01's Avatar
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 Ch# 5 Robert Lafore OOP c++

Exercise 2

Code:
#include <iostream>
   using namespace std;
   double power( double n, int p=2);   
   
   int main()
      {
      double number, answer;
      int pow;
      char yeserno;
   
      cout << "\nEnter number: ";     
      cin >> number;
      cout << "Want to enter a power (y/n)? ";
      cin >> yeserno;
      if( yeserno == ‘y’ )           
         {
         cout << "Enter power: ";
         cin >> pow;
         answer = power(number, pow);  
         }
      else
         answer = power(number);      
      cout << "Answer is " << answer << endl;
      return 0;
      }


   double power( double n, int p )
      {
      double result = 1.0;          
      for(int j=0; j<p; j++)          
         result *= n;                 
      return result;
      }


Exercise 4

Code:
#include <iostream>
using namespace std;
 
   struct Distance               
      {
      int feet;
      float inches;
      };
  
   Distance bigengl(Distance, Distance);  
   void engldisp(Distance);
   
   int main()
      {
      Distance d1, d2, d3;         
                                 
      cout << "\nEnter feet: ";  cin >> d1.feet;
      cout << "Enter inches: ";  cin >> d1.inches;
                                
      cout << "\nEnter feet: ";  cin >> d2.feet;
      cout << "Enter inches: ";  cin >> d2.inches;
   
      d3 = bigengl(d1, d2);      
                                  
      cout << "\nd1=”; engldisp(d1);
      cout << "\nd2=”; engldisp(d2);
      cout << "\nlargest is "; engldisp(d3); cout << endl;
      return 0;
      }

   Distance bigengl( Distance dd1, Distance dd2 )
      {
      if(dd1.feet > dd2.feet)      
         return dd1;               
      if(dd1.feet < dd2.feet)
         return dd2;
      if(dd1.inches > dd2.inches)           return dd1;               
      else                         
         return dd2;
      }

   void engldisp( Distance dd )
      {
      cout << dd.feet << "\’-” << dd.inches << "\””;
      }

Reply With Quote
  #3  
Old 11-09-2008, 10:44 PM
.BZU.'s Avatar


 
Join Date: Sep 2007
Location: near Govt College of Science Multan Pakistan
Posts: 9,693
Contact Number: Removed
Program / Discipline: BSIT
Class Roll Number: 07-15
.BZU. has a reputation beyond repute.BZU. has a reputation beyond repute.BZU. has a reputation beyond repute.BZU. has a reputation beyond repute.BZU. has a reputation beyond repute.BZU. has a reputation beyond repute.BZU. has a reputation beyond repute.BZU. has a reputation beyond repute.BZU. has a reputation beyond repute.BZU. has a reputation beyond repute.BZU. has a reputation beyond repute
Default Re: Solution of Ex 5 & 6 Ch# 5 Robert Lafore OOP c++

Thanks for sharing the solution..
Soooooooper.....
Here are the Questions Assigned By Madam : e:

Question 2. Raising a number n to a power p is the same as multiplying n by itself p times. Write a function called power() that takes a double value for n and an int value for p, and returns the result as a double value. Use a default argument of 2 for p, so that if this argument is omitted, the number n will be squared. Write a main() function that gets values from the user to test this function.

Question
4. Write a function that takes two Distance values as arguments and returns the larger one. Include a main() program that accepts two Distance values from the user, compares them, and displays the larger. (See the retstrc program for hints.)

Question 5. Write a function called hms_to_secs() that takes three int values—for hours, minutes, and seconds—as arguments, and returns the equivalent time in seconds (type long). Create a program that exercises this function by repeatedly obtaining a time value in hours, minutes, and seconds from the user (format 1259), calling the function, and displaying the value of seconds it returns.

Question
6. Start with the program from Exercise 11, Chapter 4, “Structures,” which adds two struct time values. Keep the same functionality, but modify the program so that it uses two functions. The first, time_to_secs(), takes as its only argument a structure of type time, and returns the equivalent in seconds (type long). The second function, secs_to_time(), takes as its only argument a time in seconds (type long), and returns a structure of type time.
__________________
(¯`v´¯)
`*.¸.*`

¸.*´¸.*´¨) ¸.*´¨)
(¸.*´ (¸.
Bzu Forum

Don't cry because it's over, smile because it happened
Reply With Quote
  #4  
Old 17-09-2008, 07:32 PM
BSIT07-01's Avatar
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
Reply

Tags
assignment, c++, ch#, lafore, oop, robert, solution


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fraction Calculator with 4 functions in c++ [ex12 of ch#5] Robert Lafore BSIT07-01 Object Oriented Programming 7 08-10-2011 10:02 AM
[Assignment] Solution Q no 1 ch#9 Object Oriented Programming in c++ by Robert Lafore BSIT07-01 Object Oriented Programming 1 15-03-2011 08:09 PM
Solution.. Raheel Quotes 0 23-02-2010 10:50 AM
NEW Fundalmentals PHYSICS Complete Solution by Halliday, Resnick, and Krane-sol_solv1 Complete Solution Nadeem Iqbal BsCS 3rd Semester 4 26-10-2009 06:10 PM
[Assignment] Q no 5 ch#9 Object Oriented Programming in c++ by Robert Lafore BSIT07-01 Object Oriented Programming 0 13-11-2008 01:02 AM

Best view in Firefox
Almuslimeen.info | BZU Multan | Dedicated server hosting
Note: All trademarks and copyrights held by respective owners. We will take action against any copyright violation if it is proved to us.

All times are GMT +5. The time now is 03:57 PM.
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.