Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Created March 1, 2026 10:43
Show Gist options
  • Select an option

  • Save thinkphp/46ee7f1845fce1ccd1dacd6cd136dc2b to your computer and use it in GitHub Desktop.

Select an option

Save thinkphp/46ee7f1845fce1ccd1dacd6cd136dc2b to your computer and use it in GitHub Desktop.
OOP clasa Masina
#include <iostream>
#include <string>
using namespace std;
class Masina {
private: //modificator de access
string marca; //date membre
int an;
double viteza;
public:
//constructorul clasei
Masina(string m, int n): marca(m), an(n), viteza(0){};
//metode
void accelereaza(double v) {viteza += v;}
void franeaza(double v) {viteza = max(0.0, viteza - v);}
void afiseaza() {
cout<<marca<<" ("<<an<<") - viteza: "<<viteza <<"km/h"<<endl;
}
};
int main() {
Masina m1("Toyota", 2020); //obiect = instanta clasei
Masina m2("BMW", 2022);
m1.accelereaza(60);
m1.franeaza(20);
m1.afiseaza(); //Toyota (2020) - Viteza: 40km/h
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment