Jump to content

Includerea Modulelor C++


skyler_sdf

Recommended Posts

Pentru a crea un program mai bine structurat, este de preferat sa asezam clasele cu metode, etc, intr-un modul(fis.h sau .cpp) dupa care in programul principal doar includem acel modul. Acest mod de lucru usureaza munca.

de ex:

#include<math.h>

class complex

{

public:

	float x, y;

	float modul();

};

float complex::modul()

{

	return sqrt(x*x+y*y);

}
#include<iostream>

#include "complex.cpp"

using namespace std;

int main()

{

	complex z;

	z.x=3;

	z.y=-6; //avem acces la x si y deoarece le am declarat de tip public in clasa complex

	cout<<z.x<<" "<<z.y<<" "<<z.modul();

	system("PAUSE");

	return 0;

}

Modulul cu functia complex il putem utiliza in felul acesta de fiecare data cand avem nevoie, fara a mai scrie inca o data codul necesar. Este de mare ajutor in cazul programelor mai mari, unde avem un cod mult mai bogat.

  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.