Institute of Computer Science
  1. Courses
  2. 2022/23 spring
  3. Programming in C++ (LTAT.03.025)
ET
Log in

Programming in C++ 2022/23 spring

  • Pealeht
  • 1. Muutujad ja andmetüübid
  • 2. Keele põhikonstruktsioonid I
  • 3. Keele põhikonstruktsioonid II
  • 4. Funktsioonimallid, failitöötlus
  • 5. OOP I Klassid
  • 6. OOP II Pärilus ja polümorfism
  • 7. Kontrolltöö 1?

Seitsmendal nädalal toimub 1. kontrolltöö

7.1 1. kontrolltöö näide?
8 Viidad. Dünaamiline mäluhaldus I?
8.1 Kodutöö?
8.2 Harjutused
8.3 Videolingid
  • 9. Dünaamiline mäluhaldus II
  • 10. Klassimallid
  • 11. STL andmestruktuurid I
  • 12. STL andmestruktuurid II
  • 13. Erindite töötlemine
  • 14. Täiendavad teemad
  • 15. Kontrolltöö 2?

Viieteistkümnendal nädalal toimub 2. kontrolltöö

15.1 2. kontrolltöö näide?
  • 16. Projekti esitlus?
  • Viiteid
  • Vanad materjalid
  • Praktikumid
  • Juhendid
  • Viited

Harjutusülesanded

1. Väärtuste vahetamine

Koosta mallifunktsioonid:

template<typename T> void vaheta_ref (T& x, T& y);
template<typename T> void vaheta_ptr (T* x, T* y);

Mõlema funktsiooni eesmärk on vahetada ära sisendina antud parameetrite väärtused.

Näide

int x = 5, y = 7;
vaheta_ref<int> (x, y);   // x = 7 ja y = 5
vaheta_ptr<int> (&x, &y); // x = 5 ja y = 7

2. Ruutvõrrandi lahendamine

Koosta funktsioonid ja katseta neid main funktsioonis.

bool lahenda_1(double a, double b, double c, double& x1, double& x2);
bool lahenda_2(double* a, double* b, double* c, double& x1, double& x2);
bool lahenda_3(double& a, double& b, double& c, double* x1, double* x2);
bool* lahenda_4(double* a, double* b, double* c, double* x1, double* x2);

Parameetritega a, b ja c on määratud võrrand ax2 + bx + c = 0. Funktsioon tagastab false, kui võrrandil ei ole reaalarvulisi lahendeid. Kui võrrandil on reaalarvulised lahendid, siis funktsioon tagastab true ning kirjutab parameetritesse x1 ja x2 võrrandi lahendid. Lahendite puudumisel x1 ja x2 väärtust ei muudeta.

NB! Funktsioonid peavad töötama ka siis, kui a = 0.

Näide ühe funktsiooni rakendamisest

double a = 1.0, b = -2.0, c = 1.0;
double x1, x2;       // lahendid on 1 ja 1
if (lahenda_1(a, b, c, x1, x2))
      cout << "Lahendid on: " << x1 << ", " << x2 << '\n';
else
      cout << "Reaalarvulisi lahendeid ei ole!" << '\n';

3. Punkt, lõik ja ringjoon

Muuda 5. nädala kodutöö klasse järgmiselt:

  • Klass Point2:
 float distanceFrom (Point2* p);
  • Klass Line2

Isendimuutujad

Point2* p1{};
Point2* p2{};

Konstruktor

 Line2(Point2* p1, Point2* p2);
  • Klass Circle2

Isendimuutuja

Point2* p1{};

Konstruktor

Circle2(Point2* p, float r);

Funktsioonid

bool contains(Point2* p);
bool contains(Line2* line);

Testi muudatusi funktsioonis main. NB! Töötama peavad ka üledefineeritud operaatorid operator<<!

  • Institute of Computer Science
  • Faculty of Science and Technology
  • University of Tartu
In case of technical problems or questions write to:

Contact the course organizers with the organizational and course content questions.
The proprietary copyrights of educational materials belong to the University of Tartu. The use of educational materials is permitted for the purposes and under the conditions provided for in the copyright law for the free use of a work. When using educational materials, the user is obligated to give credit to the author of the educational materials.
The use of educational materials for other purposes is allowed only with the prior written consent of the University of Tartu.
Terms of use for the Courses environment