LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 07-11-2004, 10:57 AM   #1
vanhelsing
Member
 
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 {
public:
Dive( float avg, float diff );
float CalcTotalPoints() const;
void Display() const;
void SetDifficulty( float diff );
void SetJudgeScore( float score );
private:
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.
D1.Display();
D2.Display();
D3.Display();

D2.SetDifficulty( 3.0 );

// Display the Dives again.
cout << "\nChanging Dive 2\n";
D1.Display();
D2.Display();
D3.Display();

return 0;
}
[root@localhost mycpp]#

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

Rep: Reputation: 0
for tutorials on how to program:
http://www.google.com/search?hl=en&i...=Google+Search
for how to compile:
http://www.google.com/search?hl=en&i...=Google+Search




www.hackerzhell.co.uk has a few C and C++ e-books available for download
 
Old 07-11-2004, 02:41 PM   #3
paulsm4
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;"
 
  


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

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

All times are GMT -5. The time now is 08:18 AM.

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