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?
  • 9. Dünaamiline mäluhaldus II
  • 10. Klassimallid
  • 11. STL andmestruktuurid I
STL andmestruktuurid I
11.1 Kodutöö
11.2 Harjutused
11.3 Videolingid
  • 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

Kodused ülesanded

1. Andmekogumite ühendamine

Koosta mallifunktsioon yhenda, mis ühendab kaks andmekogumit. Mallifunktsioonil on kolm malliparameetrit: esimesed kaks määravad ühendatavad andmekogumid ja kolmas määrab andmekogumi, kuhu kaks esimest ühendatakse. Kindlasti kasuta viiteid! Kõik kolm andmekogumit võivad olla erinevad. Mallifunktsioon peab töötama vähemalt kolmel andmekogumil: vector, list ja deque. Näide on koos järgmise ülesandega. Funktsiooni signatuur:

template <typename T1, typename T2, typename T3>
void yhenda(T1& alg1, T2& alg2, T3& tulem)

2. Andmekogumi väljundvoogu saatmine

Koosta mallifunktsioon tryki, mis saadab etteantud andmekogumi elemendid tühikuga eraldatult väljundvoogu. Mallifunktsioonil on järgmine signatuur:

template <typename T>
ostream& tryki(T& alg, ostream & os)

Näide 1. ja 2. ülesande kohta

vector<string> c1{"vector", "deque", "queue"};
deque<string> c2{"list", "forward_list", "array"};
list<string> d1;
yhenda(c1, c2, d1);
tryki(d1, cout);
 vector deque queue list forward_list array

3. Andmekogumite võrdlemine

Koosta mallifunktsioon, mis defineerib üle andmekogumite võrdlemise elementide summa alusel

template <typename T>
bool operator<(T& esimene, T& teine)

Näited andmekogumite võrdlemisest

list<int> l1{1, 5, 3, 2, 1, 1, 1};
list<int> l2{3, 5, 3, 9, 9};
cout << boolalpha << (l1 < l2) << '\n';
vector<int> v1{10, 11};
vector<int> v2{3, 5, 3};
cout << boolalpha << (v1 < v2) << '\n';
true
false
  • 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