Created
March 1, 2026 10:43
-
-
Save thinkphp/46ee7f1845fce1ccd1dacd6cd136dc2b to your computer and use it in GitHub Desktop.
OOP clasa Masina
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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