Jump to content

Recommended Posts

Posted

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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • 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.