LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-07-2004, 08:18 PM   #1
miguetoo
Member
 
Registered: Mar 2003
Location: soCal..
Distribution: lfs server.. slackware workstation..
Posts: 58

Rep: Reputation: 15
from the book..


is there something wrong with my compiler.. or is it the code..?

Code:
#include <iostream>
using namespace std;

class Distance
{
	private:
		int feet;
		float inches;
	public:
		Distance () : feet(0), inches(0.0)
		{}
		Distance (int ft, float in) : feet(ft), inches(in)
		{}
		
		void getdist()
		{
			cout << "\Enter feet: "; cin >> feet;
			cout << "Enter inches: "; cin >> inches;
		}
		void showdist()
		{	cout << feet << "\'-" << inches << '\"'; }
		
		Distance add_dist(Distance);
}

Distance Distance :: add_dist(Distance d2) // this part is giving errors..
{
	Distance temp;
	temp.inches = inches + d2.inches;
	if(temp.inches >= 12.0)
	{
		temp.inches -= 12.0;
		temp.feet = 1;
	}
	temp.feet += feet + d2.feet;
	return temp;
}

int main()
{
	Distance dist1, dist3;
	Distance dist2(11, 6.25);
	
	dist1.getdist();
	dist3 = dist1.add_dist(dist2);
	
	cout << "\ndist1 = "; dist1.showdist();
	cout << "\ndist2 = "; dist2.showdist();
	cout << "\ndist3 = "; dist3.showdist();	
	cout << endl;
	return 0;
}
i got this from a book being used in college..
 
Old 03-07-2004, 08:33 PM   #2
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
Your missing a semicolon after the closing bracket for the class definition.

Code:
class Distance {
  private:
    int feet;
    float inches;
  public:
     Distance():feet(0), inches(0.0) {
    } Distance(int ft, float in):feet(ft), inches(in) {
    }

    void getdist() {
      cout << "\Enter feet: ";
      cin >> feet;
      cout << "Enter inches: ";
      cin >> inches;
    }
    void showdist() {
      cout << feet << "'-" << inches << '\"';
    }

    Distance add_dist(Distance);
}; //<---- ERROR WAS HERE
 
Old 03-07-2004, 08:50 PM   #3
miguetoo
Member
 
Registered: Mar 2003
Location: soCal..
Distribution: lfs server.. slackware workstation..
Posts: 58

Original Poster
Rep: Reputation: 15
son of a .. thank you..
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Best book? moger Fedora 5 02-23-2005 05:53 AM
Slackware book purchase vs. URL: http://www.slackware.org/book/ jtp51 Slackware 5 11-28-2004 04:30 PM
beyond lfs book not available??? or no such book?? tuxfood Linux From Scratch 2 04-17-2004 04:12 PM
Book Ben Sytko Linux - Newbie 9 03-09-2004 06:18 PM
Which book should i get to help me out? terry.trent Linux - General 9 11-03-2003 02:26 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration