Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 07-11-2004, 11:57 AM   #1
Registered: May 2004
Posts: 130

Rep: Reputation: 15
How to compile and run my first program

I'm very newbie about c++

I have 3 file in the same folder ----->1. dive.h 2. dive.cpp 3. main.cpp

How to compile and run my main program "main.cpp"?

This is my information that make u understand me --------------->>

[root@localhost mycpp]# ls
dive.cpp dive.h main.cpp
[root@localhost mycpp]# cat dive.h
class Dive {
Dive( float avg, float diff );
float CalcTotalPoints() const;
void Display() const;
void SetDifficulty( float diff );
void SetJudgeScore( float score );
float judgeScore; //average judges score
float difficulty; //degree of difficulty
[root@localhost mycpp]# cat dive.cpp
#include "dive.h"
Dive:ive( float avg, float diff )
SetJudgeScore( avg );
SetDifficulty( diff );

void Dive:isplay() const
cout << " [Dive]: "
<< judgeScore << ','
<< difficulty << ','
<< CalcTotalPoints()
<< endl;

void Dive::SetDifficulty( float diff )
diffficulty = diff;

void Dive::SetJudgeScore ( float score )
judgeScore = score;

float Dive::CalcTotalPoints() const
return judgeScore * Difficulty;
[root@localhost mycpp]# cat main.cpp
#include "dive.h"
#include <stdio.h>
int main()
//Create three Dive objects.
Dive D1( 8.5, 3.0 );
Dive D2( 9.0, 2.5 );
Dive D3( 8.0, 3.3 );

// Display the Dives.

D2.SetDifficulty( 3.0 );

// Display the Dives again.
cout << "\nChanging Dive 2\n";

return 0;
[root@localhost mycpp]#

pls, recommend the best Toturial about c++ and OOP that easy to understand
Old 07-11-2004, 02:43 PM   #2
LQ Newbie
Registered: Mar 2004
Location: Milwaukee
Distribution: slackware 9.1
Posts: 9

Rep: Reputation: 0
for tutorials on how to program:
for how to compile: has a few C and C++ e-books available for download
Old 07-11-2004, 03:41 PM   #3
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
1. Here's the short answer to your question:

g++ -o main main.cpp dive.cpp

2. I also needed to make a few changes to the source code, including:

a) vi dive.h =>
#if !defined(_DIVE_H)
#define _DIVE_H
#endif /* _DIVE_H */

b) vi dive.cpp =>
#include <iostream>
#include <string>
#include "dive.h"
using namespace std;

c) main.cpp
<= SAME CHANGES: "#include <iostream>" .. "using namespace std;"


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
How to compile and run a java program in linux !!!! jmax24 Programming 7 08-06-2010 04:56 AM
Compile program ust Linux - General 5 05-31-2004 05:37 PM
how to compile and run c program under mandrake 9.2 ?? mschua44 Mandriva 7 02-26-2004 12:13 PM
Viewing program messages when program isn't run from command line? Locura Linux - Software 1 09-27-2003 09:19 AM
compile C program juno Linux - Software 4 09-27-2002 01:29 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:34 PM.

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