Skip to content

Commit

Permalink
Merge pull request #7 from lukasz-stepien-dev/04.01.23-assigments
Browse files Browse the repository at this point in the history
04.01.23 assigments
  • Loading branch information
lukasz-stepien-dev authored Sep 20, 2023
2 parents 2c9bf3e + 938e677 commit 0c58a6b
Show file tree
Hide file tree
Showing 7 changed files with 224 additions and 0 deletions.
49 changes: 49 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"files.associations": {
"ostream": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"random": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"new": "cpp",
"numbers": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"typeinfo": "cpp"
}
}
34 changes: 34 additions & 0 deletions 04.01.23 Assigments/Ex1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <iostream>

using namespace std;

/*Instruction
int zamien(char *lnc, char c1, char c2);
Funkcja powinna zastępować każde wystąpienie znaku c1 w łańcuchu lnc znakiem c2 i zwracać liczbę dokonanych zamian.
W funkcji main sprawdź działanie funkcji dla łańcucha i znaku podanego przez użytkownika.
*/

#define Console(x) cout << x << endl;

int change_letters(char* lnc, char c1, char c2)
{
int number_of_change = 0;
for (int i = 0; i <= sizeof(lnc) / sizeof(char); i++)
{
if (lnc[i] == c1)
{
lnc[i] = c2;
number_of_change++;
}
}
Console("Twoj ciag znaku po podmianie wyglada tak:");
Console(lnc);
return number_of_change;
}

int main()
{
char lnc[] = "aaaaaabbbbbhgsdaseyvvs";
cout << "Ilosc zmian w ciagu znaku: " << change_letters(lnc, 'a', 'c') << endl;
return 0;
}
Binary file added 04.01.23 Assigments/Ex1.exe
Binary file not shown.
66 changes: 66 additions & 0 deletions 04.01.23 Assigments/Ex2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include <iostream>
#include <cstring>

using namespace std;

/*
Instructions
Utwórz zmienna strukturalną, wypełnij ja wartościami zdefiniowanymi dla tej struktury i wyświetl je na ekranie.
A. Napisz funkcję, która przyjmuje wartość struktury pudelko i wyświetla każdą składową.
B. Napisz funkcję, która przyjmuje referencję do struktury pudelko, oblicza i ustawia składowe pole i objetosc.
*/

#define Console(x) cout << x << endl;
#define New_line cout << endl;

struct Box
{
char* name;
float height;
float width;
float length;
float area;
float volume;
};

// A
void show_data(struct Box box)
{
Console(box.name);
Console(box.height);
Console(box.width);
Console(box.length);
Console(box.area);
Console(box.volume);
}

// B
void calculate_area_and_volume(struct Box * box)
{
float height = box->height;
float width = box->width;
float length = box->length;
box->area = 2 * (height*width + width*length + height*length);
box->volume = height * width * length;
}

int main()
{
Box my_box;
strcpy(my_box.name, "Moje pudelko");
my_box.height = 5;
my_box.width = 10;
my_box.length = 3;
my_box.area = 0;
my_box.volume = 0;
Console("A:");
show_data(my_box);
New_line;
calculate_area_and_volume(&my_box);
Console("B:");
show_data(my_box);

return 0;
}
Binary file added 04.01.23 Assigments/Ex2.exe
Binary file not shown.
75 changes: 75 additions & 0 deletions 04.01.23 Assigments/Ex3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include <iostream>
#include <cstring>

using namespace std;

#define CONSOLE(x) cout << x << endl;

struct Person
{
void set_first_name(char * letter)
{
*first_name = *letter;
}

void set_last_name(char text[])
{
strcpy(last_name, text);
}

void set_pesel(char text[])
{
strcpy(pesel, text);
}

char get_first_name()
{
return *first_name;
}

char* get_last_name()
{
return last_name;
}

char* get_pesel()
{
return pesel;
}

private:
char * first_name;
char last_name[30];
short age;
char pesel[10];
};

int main()
{
Person person1;
const short year = 2023;
char first_name;
char c_last_name[30];
char c_pesel[10];
string s_last_name;
string s_pesel;


CONSOLE("Podaj swoj inicjal imienia:");
cin >> first_name;
CONSOLE("Podaj swoje nazwisko:");
cin.ignore();
getline(cin, s_last_name);
strcpy(c_last_name, s_last_name.c_str());
CONSOLE("Podaj swoj PESEl (spokojnie bedzie u nas bezpieczny):");
cin >> s_pesel;
strcpy(c_pesel, s_pesel.c_str());

person1.set_first_name(&first_name);
person1.set_last_name(c_last_name);
person1.set_pesel(c_pesel);
CONSOLE(person1.get_first_name());
CONSOLE(person1.get_last_name());
CONSOLE(person1.get_pesel());
return 0;
}
Binary file added 04.01.23 Assigments/Ex3.exe
Binary file not shown.

0 comments on commit 0c58a6b

Please sign in to comment.