 |
www.polcz.fora.pl pcz
|
Zobacz poprzedni temat :: Zobacz następny temat |
Autor |
Wiadomość |
gosel
Dołączył: 28 Paź 2008
Posty: 87
Przeczytał: 0 tematów
Pomógł: 1 raz Ostrzeżeń: 0/5
|
Wysłany: Sob 12:18, 07 Lis 2009 Temat postu: 1 lab programy |
|
|
Kod: |
// Hello.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "iostream"
using namespace std;
class Macierz
{
private:
int _t[5][5];
public:
Macierz()
{
cout<<"Podaj dane macierzy: "<<endl;
for (int x=0;x<=4;x++)
for (int y=0;y<=4;y++)
{
cout<<"["<<x<<"]["<<y<<"]:"<<endl;
cin>>this->_t[x][y];
}
}
void pokaz()
{
cout<<endl<<"wyswietlanie macierzy"<<endl<<endl;
for (int x=0;x<=4;x++)
{
for (int y=0;y<=4;y++)
{
cout<<this->_t[x][y]<<" ";
}
cout<<endl;
}
}
void przekatna()
{
cout<<endl<<"wyswietlanie przekatnej"<<endl<<endl;
for (int x=0;x<=4;x++)
cout<<this->_t[x][x];
cout<<endl;
}
};
int main()
{
Macierz t;
// menu
cout<<endl<<"*** MENU ***"<<endl;
cout<<"*** 1 - wyswietlanie calej macierzy ***"<<endl;
cout<<"*** 2 - wyswietlanie przekatnej ***"<<endl;
cout<<"*** q - wyjscie ***"<<endl<<endl;
char a;
cin>>a;
while (a!='q')
{
switch (a){
case '1': t.pokaz();break;
case '2': t.przekatna();break;
default: cout<<"!!! zle polecenie !!!"<<endl<<endl;
}
cin>>a;
}
return 0;
}
|
Post został pochwalony 0 razy
Ostatnio zmieniony przez gosel dnia Sob 12:36, 07 Lis 2009, w całości zmieniany 2 razy
|
|
Powrót do góry |
|
 |
|
 |
gosel
Dołączył: 28 Paź 2008
Posty: 87
Przeczytał: 0 tematów
Pomógł: 1 raz Ostrzeżeń: 0/5
|
Wysłany: Sob 14:22, 07 Lis 2009 Temat postu: |
|
|
Kod: |
// Hello.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "math.h"
#include "iostream"
using namespace std;
class Macierz
{
private:
int _t[5][5];
public:
Macierz()
{
cout<<"Podaj dane macierzy: "<<endl;
for (int x=0;x<=4;x++)
for (int y=0;y<=4;y++)
{
cout<<"["<<x<<"]["<<y<<"]:"<<endl;
cin>>this->_t[x][y];
}
}
void pokaz()
{
cout<<endl<<"wyswietlanie macierzy"<<endl<<endl;
for (int x=0;x<=4;x++)
{
for (int y=0;y<=4;y++)
{
cout<<this->_t[x][y]<<" ";
}
cout<<endl;
}
}
void przekatna()
{
cout<<endl<<"wyswietlanie przekatnej"<<endl<<endl;
for (int x=0;x<=4;x++)
cout<<this->_t[x][x]<<" ";
cout<<endl;
}
};
class RownKwad
{
private:
float _a,_b,_c;
float _x1,_x2;
public:
RownKwad()
{
cout<<"Podaj a: ";
cin>>this->_a;
cout<<"Podaj b: ";
cin>>this->_b;
cout<<"Podaj c: ";
cin>>this->_c;
}
void rozwiaz()
{
float d2=(this->_b*this->_b)-(4*(this->_a*this->_c));
if (d2<0)
{
cout<<"Brak rozwiazania - delta ujemna = "<<d2<<endl<<endl;
this->_x1=this->_x2=-1.0;
}
else if (d2==0)
{
this->_x1=this->_x2=-this->_b/2*this->_a;
cout<<"x = "<<this->_x1<<endl<<endl;
}
else
{
this->_x1=-this->_b+sqrt(d2)/2*this->_a;
this->_x2=-this->_b-sqrt(d2)/2*this->_a;
cout<<"x1 = "<<this->_x1<<endl;
cout<<"x2 = "<<this->_x2<<endl<<endl;
}
}
};
int main()
{
cout<<endl<<"*** MENU ***"<<endl;
cout<<"*** 1 - rownanie kwadratowe ***"<<endl;
cout<<"*** 2 - macierz ***"<<endl;
cout<<"*** q - wyjscie ***"<<endl<<endl;
char b;
cin>>b;
while (b!='q')
{
switch (b)
{
case '1':{RownKwad r;r.rozwiaz();}break;
case '2':
{Macierz t;
// menu
cout<<endl<<"*** MENU ***"<<endl;
cout<<"*** 1 - wyswietlanie calej macierzy ***"<<endl;
cout<<"*** 2 - wyswietlanie przekatnej ***"<<endl;
cout<<"*** q - wyjscie ***"<<endl<<endl;
char a;
cin>>a;
while (a!='q')
{
switch (a){
case '1': t.pokaz();break;
case '2': t.przekatna();break;
default: cout<<"!!! zle polecenie !!!"<<endl<<endl;break;
}
cin>>a;
}
}
break;
default: cout<<"!!! zle polecenie !!!"<<endl<<endl;break;
}
cin>>b;
}
return 0;
}
|
Post został pochwalony 0 razy
Ostatnio zmieniony przez gosel dnia Sob 14:23, 07 Lis 2009, w całości zmieniany 1 raz
|
|
Powrót do góry |
|
 |
|
|
Nie możesz pisać nowych tematów Nie możesz odpowiadać w tematach Nie możesz zmieniać swoich postów Nie możesz usuwać swoich postów Nie możesz głosować w ankietach
|
fora.pl - załóż własne forum dyskusyjne za darmo
Powered by phpBB © 2001, 2002 phpBB Group
|