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

Register FAQ Community Calendar New Posts Navbar Right Corner
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


 
 
Thread Tools Search this Thread Rating: Thread Rating: 6 votes, 4.67 average. Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 11-09-2008, 09:29 PM
BSIT07-01's Avatar
Addicted to Computer


 
Join Date: Sep 2007
Location: ------------
Age: 36
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
 

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


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

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 12:56 AM.
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.