Skip to content

Commit

Permalink
Restructure according to Fall 1403 calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
ramtung committed Sep 13, 2024
1 parent 5256065 commit ef4de03
Show file tree
Hide file tree
Showing 372 changed files with 158,611 additions and 437 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.DS_Store
*.out
**/notes
**/recitation
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 18 additions & 0 deletions 01_TerminalIO_Strings/05_StringBasics.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <iostream>
#include <string>
using namespace std;

int main() {
string s = "abcdef";
cout << s.length() << endl;
cout << s[2] << endl;

cout << s.substr(1, 2) << endl;
cout << s.substr(1) << endl;

cout << s.find('c') << endl;
if (s.find('D') == string::npos)
cout << "Not found!" << endl;

return 0;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,67 +10,26 @@ int main()
vec.push_back(1.3);
vec[0] = 12.4;









vector<int> v(6);

v[0] = 5;
v[1] = 7;
v[2] = 9;
v[3] = 4;
v[4] = 6;
v[5] = 8;







vector<int> w = {5, 7, 9, 4, 6, 8}; // C++11 or higher

vector<string> philosopher(4);

philosopher [0] = "Kant";
philosopher [1] = "Plato";
philosopher [2] = "Hume";
philosopher [3] = "Kierkegaard";

//philosopher[2] = 99;








vector<double> vd(1000, 1.2);
//vd[1000] = 4.7;

















vector<vector<int> > twod(5);

twod[0].push_back(12);
twod[0].push_back(45);
twod[1].push_back(3);
Expand All @@ -83,15 +42,5 @@ int main()
[1, 6]
[]
[]
*/
}









Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#include <vector>
#include <string>
#include <iostream>
using namespace std;

int main()
{
// C++11 Syntax:
int main() {
vector<int> v = {1, 3, 6, 2};

for (int i = 0; i < v.size(); i++)
cout << v[i] << ' ';
cout << endl;

for (int x : v)
cout << x << ' ';
cout << endl;
Expand Down
18 changes: 18 additions & 0 deletions 02_Containers_Iterators/03_VectorIterators.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <vector>
#include <iostream>
using namespace std;

int main() {
vector<int> v = {1, 3, 6, 2};

vector<int>::iterator it = v.begin();
while (it != v.end()) {
cout << *it << ' ';
++it;
}
cout << endl;

for (auto it2 = v.begin(); it2 != v.end(); it2++)
cout << *it2 << ' ';
cout << endl;
}
20 changes: 20 additions & 0 deletions 02_Containers_Iterators/04_Lists.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <list>
#include <iostream>
using namespace std;

int main() {
list<int> l = {1, 3, 6, 2};

list<int>::iterator it = l.begin();
while (it != l.end()) {
cout << *it << ' ';
++it;
}
cout << endl;

l.push_front(12);
for (auto it2 = l.begin(); it2 != l.end(); it2++)
cout << *it2 << ' ';
cout << endl;

}
13 changes: 13 additions & 0 deletions 02_Containers_Iterators/05_VectorAllocation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <vector>
#include <iostream>
using namespace std;

int main()
{
vector<double> v;
for (int i = 0; i < 20; i++) {
cout << i << "\tsize = " << v.size()
<< "\tcapacity = " << v.capacity() << endl;
v.push_back(0);
}
}
32 changes: 32 additions & 0 deletions 02_Containers_Iterators/06_VectorAppendTiming.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <vector>
#include <list>
#include <iostream>
#include <chrono>

using namespace std;
using namespace chrono;

int main()
{
vector<double> v;
for (int i = 0; i < 10000; i++) {
cout << i << "\tsize = " << v.size()
<< "\tcapacity = " << v.capacity();

steady_clock::time_point begin = steady_clock::now();
v.push_back(0);
steady_clock::time_point end = steady_clock::now();
cout << "\ttime = " << duration_cast<nanoseconds>(end-begin).count() << "[ns]" << endl;
}

list<double> l;
for (int i = 0; i < 10000; i++) {
cout << i << "\tsize = " << l.size();

steady_clock::time_point begin = steady_clock::now();
l.push_back(0);
steady_clock::time_point end = steady_clock::now();
cout << "\ttime = " << duration_cast<nanoseconds>(end-begin).count() << "[ns]" << endl;
}

}
32 changes: 32 additions & 0 deletions 02_Containers_Iterators/07_ListAppendTiming.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <vector>
#include <list>
#include <iostream>
#include <chrono>

using namespace std;
using namespace chrono;

int main()
{
vector<double> v;
for (int i = 0; i < 10000; i++) {
cout << i << "\tsize = " << v.size()
<< "\tcapacity = " << v.capacity();

steady_clock::time_point begin = steady_clock::now();
v.push_back(0);
steady_clock::time_point end = steady_clock::now();
cout << "\ttime = " << duration_cast<nanoseconds>(end-begin).count() << "[ns]" << endl;
}

list<double> l;
for (int i = 0; i < 10000; i++) {
cout << i << "\tsize = " << l.size();

steady_clock::time_point begin = steady_clock::now();
l.push_back(0);
steady_clock::time_point end = steady_clock::now();
cout << "\ttime = " << duration_cast<nanoseconds>(end-begin).count() << "[ns]" << endl;
}

}
22 changes: 22 additions & 0 deletions 02_Containers_Iterators/08_Map.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <map>
#include <iostream>

using namespace std;

int main() {
map<string, double> grades;
grades["Hooshang"] = 12.3;
grades["Mahvash"] = 16;

cout << grades["Hooshang"] << endl;
cout << grades["Esfandiar"] << endl;
// cout << grades.at("Shahnaz") << endl;
cout << grades.size() << endl;

for (auto it = grades.begin(); it != grades.end(); it++)
cout << it->first << "'s grade is " << it->second << endl;

map<char, int> cc = {{'a', 4}, {'x', 3}, {'i', 1}};
for (auto it2 = cc.begin(); it2 != cc.end(); it2++)
cout << it2->first << "->" << it2->second << endl;
}
24 changes: 24 additions & 0 deletions 03_Algorithms_Lambdas/01_BasicAlgorithms.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <algorithm>
using namespace std;

int main() {
vector<int> v = {1, 3, 2, 6, 12, 8};
list<string> l = {"Gholi", "aroosi", "naraft!"};

vector<int>::iterator it = find(v.begin(), v.end(), 6);
if (it != v.end())
cout << "found!" << endl;

if (find(l.begin(), l.end(), "Gholi") != l.end())
cout << "found!" << endl;

// The following line causes a compile error! How can we fix it?
replace(l.begin(), l.end(), "Gholi", "Shahpar");

for (auto it = l.begin(); it != l.end(); it++)
cout << *it << ' ';
}
16 changes: 16 additions & 0 deletions 03_Algorithms_Lambdas/02_ForEachPrint.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <iostream>
#include <string>
#include <list>
#include <algorithm>
using namespace std;

int main() {
list<string> l = {"Gholi", "aroosi", "naraft!"};

replace(l.begin(), l.end(), string("Gholi"), string("Shahpar"));

for_each(l.begin(), l.end(), [](string s){ cout << s << ' '; });

// for (auto it = l.begin(); it != l.end(); it++)
// cout << *it << ' ';
}
13 changes: 13 additions & 0 deletions 03_Algorithms_Lambdas/03_FindIf.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <iostream>
#include <string>
#include <list>
#include <algorithm>
using namespace std;

int main() {
list<string> l = {"Gholi", "aroosi", "naraft!"};

auto it = find_if(l.begin(), l.end(), [](string s){ return s.length() % 2 == 1; });
if (it != l.end())
cout << *it << endl;
}
13 changes: 13 additions & 0 deletions 03_Algorithms_Lambdas/04_FindIf_Last.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <iostream>
#include <string>
#include <list>
#include <algorithm>
using namespace std;

int main() {
list<string> l = {"Gholi", "aroosi", "naraft!"};

auto it = find_if(l.rbegin(), l.rend(), [](string s){ return s.length() % 2 == 1; });
if (it != l.rend())
cout << *it << endl;
}
File renamed without changes.
File renamed without changes.
16 changes: 0 additions & 16 deletions 03_Func/01_PassByVal.cpp

This file was deleted.

20 changes: 0 additions & 20 deletions 03_Func/02_PassByRef.cpp

This file was deleted.

Loading

0 comments on commit ef4de03

Please sign in to comment.