Regisztráció Blogot indítok
Adatok
marwellazure

0 bejegyzést írt és 18 hozzászólása volt az általa látogatott blogokban.

Admin Szerkesztő Tag Vendég
"Alighogy átszállt a határon a győzelem, az a hat-három s fáradtan a nagy drukkolástól ledőlnék, egyszer csak rámszól a rádió és arra bíztat, hogy verset írjak... Hát írok is." Zelk Zoltán: Rímes üdvözlő távirat http://www.mtv.hu/modernkepmesek/cikk.php?id=165709…..
Ez az ötödik hét (labor és előadás) posztja. Remek ötletként vezetjük be azt a "laborkártyát", hogy a "saját" focicsapat megléte és elhozása az órára maga is egy ilyen kártya legyen! Természetesen ezt a bónusz kártyát mindenkinek kiosztjuk a labor…..
„The 600 series had rubber skin. We spotted them easy. But these are new. They look human. Sweat, bad breath, everything. Very hard to spot.”T E R M I N A T O RA mai laboron már (informatikus majdnem**) olyan fejlett ágenseket készítünk, amik analógiái az idézet "Cyber…..
Here we pass the ball, you understand that? We're a unit, not a one-man show. The name on the front of the shirt is more important than the one on the back. Erik Dornhelm, GOAL, http://www.imdb.com/title/tt0380389/quotes Ez a harmadik hét (labor és előadás) posztja. A hét feladata az előző…..
Íme a negyedik hullám, de élvezd az elsőt, a másodikat és a harmadikat is! (Ha mást nem mondunk, akkor a szokásos "hegylakó szabály" van: csak egy maradhat, azaz az első vadászé a trófea.) Továbbá, ha mást nem mondunk, akkor a jelen hullám feladatainak megoldását is C,…..
marwellazure 2011.04.18 21:23:28
#include <string>
#include <cctype>
#include<iostream>
#include<map>

using namespace std;

int no_of_errors;

double error(const char* s)
{
no_of_errors++;
cerr << "error: " << s << '\n';
return 1;
}

enum Token_value {
NAME, NUMBER, END,
PLUS='+', MINUS='-', MUL='*', DIV='/',
PRINT=';', ASSIGN='=', LP='(', RP=')'
};

Token_value curr_tok = PRINT;
double number_value;
string string_value;

/*

Token_value get_token()
{
char ch = 0;
cin>>ch;

switch (ch) {
case 0:
return curr_tok=END;
case ';':
case '*':
case '/':
case '+':
case '-':
case '(':
case ')':
case '=':
return curr_tok=Token_value(ch);
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
case '.':
cin.putback(ch);
cin >> number_value;
return curr_tok=NUMBER;
default:
if (isalpha(ch)) {
cin.putback(ch);
cin>>string_value;
return curr_tok=NAME;
}
error("bad token");
return curr_tok=PRINT;
}
}
*/

Token_value get_token()
{
char ch;

do {
if(!cin.get(ch)) return curr_tok = END;
} while (ch!='\n' && isspace(ch));

switch (ch) {
case ';':
case '\n':
return curr_tok=PRINT;
case '*':
case '/':
case '+':
case '-':
case '(':
case ')':
case '=':
return curr_tok=Token_value(ch);
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
case '.':
cin.putback(ch);
cin >> number_value;
return curr_tok=NUMBER;
default:
if (isalpha(ch)) {
string_value = ch;
while (cin.get(ch) && isalnum(ch))
string_value += ch;

cin.putback(ch);
return curr_tok=NAME;
}
error("bad token");
return curr_tok=PRINT;
}
}

map<string,double> table;

double expr(bool);

double prim(bool get)
{
if (get) get_token();

switch (curr_tok) {
case NUMBER:
{ double v = number_value;
get_token();
return v;
}
case NAME:
{ double& v = table[string_value];
if (get_token() == ASSIGN) v = expr(true);
return v;
}
case MINUS:
return -prim(true);
case LP:
{ double e = expr(true);
if (curr_tok != RP) return error(") expected");
get_token();
return e;
}
default:
return error("primary expected");
}
}

double term(bool get)
{
double left = prim(get);

for (;;)
switch (curr_tok) {
case MUL:
left *= prim(true);
break;
case DIV:
if (double d = prim(true)) {
left /= d;
break;
}
return error("divide by 0");
default:
return left;
}
}

double expr(bool get)
{
double left = term(get);

for (;;)
switch (curr_tok) {
case PLUS:
left += term(true);
break;
case MINUS:
left -= term(true);
break;
default:
return left;
}
}

int main()
{

table["pi"] = 3.1415926535897932385;
table["e"] = 2.7182818284590452354;

while (cin) {
get_token();
if (curr_tok == END) break;
if (curr_tok == PRINT) continue;
cout << expr(false) << '\n';
}

return no_of_errors;
}
marwellazure 2011.04.18 23:13:16
(ÉLES) B&L(**) 7/Sorter feladat:142. oldal (másik két "7/"-el egymást kizáró.)

noob.hu/2011/04/18/Sorter.png

A hozzá tartozó források pedig:

//IComparable.h
#ifndef ICOMPARABLE_H
#define ICOMPARABLE_H

class IComparable
{

public:
virtual bool operator<(const IComparable&) = 0;
};

#endif /*
*/

//Person.h
#ifndef PERSON_H
#define PERSON_H
#include "IComparable.h"

class Person:public IComparable
{

unsigned char age;
double height;
double weight;
public:Person (unsigned char age, double height, double weight):
age(age),height(height),weight(weight){}

bool SetHeight (double height);
double GetHeight(){return height;}

bool SetWeight (double weight);
double GetWeight(){return weight;}

bool SetAge (unsigned char age);
unsigned char GetAge(){return age;}

bool operator<(const IComparable& theOther)
{
return age < ((Person&) theOther).age;
}
};

#endif /*
*/

//Sorter.h
#ifndef SORTER_H
#define SORTER_H
#include "IComparable.h"

class Sorter
{

public:
static void BubbleSort(IComparable** pItems, unsigned itemCount);

};

#endif /*
*/

//main.cpp

#include <iostream>
#include "Person.h"
#include "Sorter.h"
using namespace std;
int
main (void)
{
const unsigned maxPeople = 4;
Person* people[maxPeople];

people[0] = new Person (56,100,50);
people[1] = new Person (12,180,85);
people[2] = new Person (4,182,90);
people[3] = new Person (22,182,90);

IComparable* comparables[maxPeople];
unsigned int i;
for (i = 0; i < maxPeople; i++)
comparables[i] = people[i];

Sorter::BubbleSort(comparables, maxPeople);

for (unsigned int i = 0; i < maxPeople; i++)
{
Person* pPerson = (Person*) comparables[i];
cout << (int) pPerson->GetAge () << ',' << (int) pPerson->GetHeight ()<< ',' <<(int) pPerson->GetWeight () << ',' << '\n';
}

for (unsigned int i = 0; i < maxPeople; i++)
delete people[i];
}

//Sorter.cpp
#include "Sorter.h"
void
Sorter::BubbleSort (IComparable** pItems, unsigned itemCount)
{

for (unsigned int j = itemCount; j > 0; j--)

{

for (unsigned int i = 1; i < j; i++)

{

if (*pItems[i] < *pItems[i - 1])
{

IComparable* tmp = pItems[i];
pItems[i] = pItems[i-1];
pItems[i-1] = tmp;

}
}
}
}
Laborvezetőknek A 3. előadás laborkártyáit kérdezzük végig a hallgatóktól (és persze a korábbiakból is osszunk ki, amelyeket fontosnak érezünk). Ha indokolt, akkor bevezethető a több sebességes labor, ahol az előre készülő hallgatók későbbi feladatokkal dolgoznak, vagy…..