Tanár úr lebetegedett, úgyhogy az óra elmaradt. Illetve bejött, adott egy vektoros feladatot, aztán elengedte a csapatot.
Számítógépes alapismeretek 2. - 3. óra
március 2, 2012 13:11
Az oldal töltődik…
Tanár úr lebetegedett, úgyhogy az óra elmaradt. Illetve bejött, adott egy vektoros feladatot, aztán elengedte a csapatot.
https://docs.google.com/document/d/1B-kSmTuQu89YU8XOb72IlyRp3PL1NpzvBGdLt4UxfcE/edit
#include <iostream>#include <vector>#include <cstdlib>using namespace std;void beolvasas(vector< vector<int> > &jegyek);
int beolvas_egesz(const string uzenet, const string hibauzenet);
int beolvas_jegy(const int i, const int j);
bool fel11a(const vector< vector<int> > jegyek);
bool csupaotos(const int i, const vector< vector<int> > jegyek);
int main(){
vector< vector<int> > jegyek; // a két záró kacsacsõr közé mindenképp kell a szóköz
bool van;beolvasas(jegyek);
van = fel11a(jegyek);
if (van){
cout << "Van" << endl;
} else {
cout << "Nincs" << endl;
}return 0;
}bool fel11a(const vector< vector<int> > jegyek){
int i=0;
int n=jegyek.size();
while(i<=(n-1) && !csupaotos(i, jegyek)){
i++; }return i<=n-1;
}bool csupaotos(const int i, const vector< vector<int> > jegyek){
int j=0;
int m=jegyek[i].size();
while((j<=(m-1)) && (jegyek[i][j]==5)){
j++; }return j>(m-1);
}void beolvasas(vector< vector<int> > &jegyek){
int n, m;
n = beolvas_egesz("Hany diak: ", "Nem negativ kell!");
m = beolvas_egesz("Hany targy: ", "Nem negativ kell!");
jegyek.resize(n);
for(int i=0; i<n; i++){
jegyek[i].resize(m);
for(int j=0; j<m; j++){
jegyek[i][j] = beolvas_jegy(i,j);
} }}int beolvas_egesz(const string uzenet, const string hibauzenet){
int n;
bool hiba;do{
cout << uzenet;
string str;cin >> str;
n = atoi(str.c_str()); // atof float-hoz
hiba = n==0 && str!="0" || n<0;
if(hiba){
cout << hibauzenet << endl;
}} while(hiba);
return n;
}int beolvas_jegy(const int i, const int j){
int n;
bool hiba;do{
cout << i+1 << ". diak " << j+1 << ". jegye: ";
string str;cin >> str;
n = atoi(str.c_str()); // atof float-hoz
hiba = n==0 && str!="0" || n<1 || n>5;
if(hiba){
cout << "1 es 5 kozott kell lennie!" << endl;
}} while(hiba);
return n;
}https://docs.google.com/document/d/1K3prpp0qocb92dNuJ6oFQBAgRSyhjTTG3CaPC1ppr3k/edit
void strcpy(char * D, const char * s);
int main(){
char T[10];
strcpy(T, "valami");
cout << T;
return 0;
}void strcpy(char * D, const char * s){
for(int i=0;s[i]!=' ';++i){
D[i]=s[i];
}}Áttértünk a C-re.
A jegyzet: https://docs.google.com/document/d/1vAZ-p2yapQcnIQUr_0WKtGQxz0lb7pI6yB6-Z2qkT4c/edit
#include <stdio.h>#include <stdlib.h>#include <string.h>int main(int AGC, char * ARGV[]){
char s1[20]; char s[200]; int egy;
strcpy(s," ");
do{
printf("Kerem a szovegeket: ");
scanf("%s", &s1);
egy=strcmp(s1, "vege");
if(egy!=0){
strcat(s,s1);
}} while (egy!=0);
printf("Az osszemasolt szoveg: %sn", s);
return 0;
}#include <stdio.h> #include <stdlib.h> #include <string.h> int main(int AGC, char * ARGV[]){ char s1[20]; char s[200]; int egy; char ch[2]; int db=0; strcpy(s," "); printf("Kerem a vizsgalando szoveget: "); gets(ch); do{ printf("Kerem a szovegeket: "); scanf("%s", &s1); egy=strcmp(s1, "vege"); if(egy!=0){ strcat(s,s1); } if(s1[0]==ch[0]){ db=db+1; } } while (egy!=0); // printf("Az osszemasolt szoveg: %sn", s); printf("A keresett elemek szama: %dn", db); return 0; }
https://docs.google.com/document/d/1H8-kF2jE0MuSrao__M93YroymuTdUKxdNlAeak5MHOk/edit
#include <iostream>#include <fstream>#include <vector>using namespace std;void beolvasas(vector<double> &x);
void beolvasas_file(vector<double> &x);
void fel1(const vector<double> hom, double &atlag);
void fel3(const vector<double> hom, int &leghidegebbnap);
void fel7(const vector<double> hom, bool &van, int &ind);
void ellkiiras(const vector<double> &hom);
int main()
{ //double hom[MAXN];vector<double> hom;
//beolvasas(hom);beolvasas_file(hom);
ellkiiras(hom);
double atlag;
fel1(hom, atlag);
cout << "Atlaghom= " << atlag << endl;
int leghidegebbnap;
fel3(hom, leghidegebbnap);
cout << "Leghidegebbnap= " << leghidegebbnap << endl;
bool van;int ind;
fel7(hom, van, ind);
if (van)
{cout << "= a szomszedjaval: " << ind << endl;
} else {cout << "Nincs = a szomszedjaval" << endl;
}return 0;
}void beolvasas(vector<double> &x)
{int n;
cout << "n=";
cin >> n;
x.resize(n);
for (int i=0; i<n; ++i)
{cout << i << ". hom: ";
cin >> x[i];
}}void beolvasas_file(vector<double> &x)
{double sv;
//ifstream f("be.txt"); ifstream f; string fajlnev; bool hiba; do {cout << "Fajlnev: ";
cin >> fajlnev;
f.open(fajlnev.c_str());
hiba=f.fail();
if (hiba)
{cout << "Nem jo fajlnev" << endl;
} }while(hiba);
/*while (!f.eof()) { f >> sv; if (f.good()) { x.push_back(sv); } }*/f >> sv;
while (!f.eof())
{x.push_back(sv);
f >> sv;
}f.close();
}void ellkiiras(const vector<double> &hom)
{for (int i=0; i<hom.size(); ++i)
{cout << i << ".: " << hom[i] << endl;
}}void fel1(const vector<double> hom, double &atlag)
{double s=0;
int n=hom.size();
for (int i=0; i<n; ++i)
{s+=hom[i];
}atlag=s/n;
}void fel3(const vector<double> hom, int &leghidegebbnap)
{double max=hom[0];
leghidegebbnap=0;
for (int i=0; i<hom.size(); ++i)
{if (hom[i]<max)
{leghidegebbnap=i;
max=hom[i];
} }}void fel7(const vector<double> hom, bool &van, int &ind)
{ind=0;
while (ind<hom.size() && hom[ind]!=hom[ind+1])
{++ind;
}van=ind<hom.size();
}