Created
May 25, 2017 18:02
-
-
Save Mati365/f10f3807fd92ca43334e5f8bbf02ff05 to your computer and use it in GitHub Desktop.
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
1) Jan Kowalski dostał oceny z polskiego, angielskiego i fizyki. Jeśli | |
< 2 - tragedia | |
<= 2; 3> - jako tako | |
<= 3, 4 >= środkowa | |
< 4 super | |
srednia wazona, | |
2) Takie jak 1 tylko z user sam sobie dodaje przedmioty | |
3) tab 10x10, całkowite, 0 -100, licznik, parzyste | |
4) takie jak pierwsze i min, max współrzędnych wierzchołków | |
1) | |
#include <cstdlib> | |
#include <iostream> | |
#include <vector> | |
using std::cout; | |
using std::cin; | |
using std::endl; | |
struct Lesson; | |
typedef std::vector<Lesson> Lessons; | |
struct Lesson { | |
std::string name; | |
short grade; | |
short weight; | |
Lesson& enter() { | |
cout << "Wprowadz ocene i wage dla przedmiotu " << this->name << endl; | |
cout << "Ocena: "; cin >> this->grade; | |
cout << "Waga: "; cin >> this->weight; | |
return *this; | |
} | |
static float getAverage(const Lessons& lessons) { | |
float sum = 0, | |
weights = 0; | |
for (short i = 0;i < lessons.size();++i) { | |
weights += (int)lessons[i].weight; | |
sum += (int)lessons[i].grade * (int)lessons[i].weight; | |
} | |
return sum / weights; | |
} | |
static std::string toString(const float& avg) { | |
if (avg < 0) return "tragedia"; | |
else if (avg >= 2 && avg < 3) return "jako tako"; | |
else if (avg >= 3 && avg <= 4) return "srodkowa"; | |
else return "super"; | |
} | |
static void prompt() { | |
cout << "Wpisuj kolejno przedmioty z ktorych chcesz miec srednia wazona:" | |
<< endl; | |
const Lesson t[] = { | |
{name: "Polski"}, | |
{name: "Angielski"}, | |
{name: "Fizyka"} | |
}; | |
Lessons lessons(t, t + sizeof(t) / sizeof(t[0])); | |
for(int i = 0;i < lessons.size();++i) { | |
lessons[i].enter(); | |
} | |
const float avg = Lesson::getAverage(lessons); | |
cout | |
<< "Twoja srednia to " | |
<< avg | |
<< " i jest to " | |
<< Lesson::toString(avg) | |
<< endl; | |
} | |
}; | |
int main(int argc, char *argv[]) | |
{ | |
Lesson::prompt(); | |
system("PAUSE"); | |
return EXIT_SUCCESS; | |
} | |
2) | |
#include <cstdlib> | |
#include <iostream> | |
#include <vector> | |
using std::cout; | |
using std::cin; | |
using std::endl; | |
struct Lesson; | |
typedef std::vector<Lesson> Lessons; | |
struct Lesson { | |
std::string name; | |
short grade; | |
short weight; | |
static Lesson enter() { | |
Lesson tmp = {"", 0, 0}; | |
cout << "Nazwa: "; cin >> tmp.name; | |
cout << "Ocena: "; cin >> tmp.grade; | |
cout << "Waga: "; cin >> tmp.weight; | |
return tmp; | |
} | |
static float getAverage(const Lessons& lessons) { | |
float sum = 0, | |
weights = 0; | |
for (short i = 0;i < lessons.size();++i) { | |
weights += (int)lessons[i].weight; | |
sum += (int)lessons[i].grade * (int)lessons[i].weight; | |
} | |
return sum / weights; | |
} | |
static std::string toString(const float& avg) { | |
if (avg < 0) return "tragedia"; | |
else if (avg >= 2 && avg < 3) return "jako tako"; | |
else if (avg >= 3 && avg <= 4) return "srodkowa"; | |
else return "super"; | |
} | |
static void prompt() { | |
cout << "Wpisuj kolejno przedmioty z ktorych chcesz miec srednia wazona:" | |
<< endl; | |
Lessons lessons; | |
while(true) { | |
lessons.push_back(Lesson::enter()); | |
cout << "Koniec? Jesli tak to t, jesli n to nie wpisz" << endl; | |
char operation; | |
cin >> operation; | |
if(operation == 't') | |
break; | |
} | |
const float avg = Lesson::getAverage(lessons); | |
cout | |
<< "Twoja srednia to " | |
<< avg | |
<< " i jest to " | |
<< Lesson::toString(avg) | |
<< endl; | |
} | |
}; | |
int main(int argc, char *argv[]) | |
{ | |
Lesson::prompt(); | |
system("PAUSE"); | |
return EXIT_SUCCESS; | |
} | |
3) i 4) | |
#include <cstdlib> | |
#include <iostream> | |
#include <stdlib.h> | |
#include <time.h> | |
using std::cout; | |
using std::cin; | |
using std::endl; | |
int main(int argc, char *argv[]) | |
{ | |
srand(time(NULL)); | |
int tab[10][10], parity = 0; | |
for (int i = 0;i < 10;++i) { | |
for (int j = 0;j < 10;++j) { | |
tab[i][j] = rand() % 100; | |
parity += !(tab[i][j] % 2) ? 1 : 0; | |
} | |
} | |
cout << "Parzystych: " << parity << endl; | |
system("PAUSE"); | |
return EXIT_SUCCESS; | |
} | |
4) 5) #include <cstdlib> | |
#include <iostream> | |
#include <stdlib.h> | |
#include <time.h> | |
using std::cout; | |
using std::cin; | |
using std::endl; | |
struct vec { int x, y, val; }; | |
int main(int argc, char *argv[]) | |
{ | |
srand(time(NULL)); | |
vec max = {0, 0, -1}; | |
vec min = {0, 0, -1}; | |
int tab[10][10]; | |
for (int i = 0;i < 10;++i) { | |
for (int j = 0;j < 10;++j) { | |
tab[i][j] = rand() % 100; | |
if (tab[i][j] >= max.val || max.val == -1) { | |
max = (vec){i, j, tab[i][j]}; | |
} | |
if(tab[i][j] <= min.val || min.val == -1) { | |
min = (vec){i, j, tab[i][j]}; | |
} | |
} | |
} | |
cout << "max: " << max.val << " wspolrzedne: (" << max.x << ", " << max.y << ")" << endl; | |
cout << "min: " << min.val << " wspolrzedne: (" << min.x << ", " << min.y << ")" << endl; | |
system("PAUSE"); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment