úprava programu
Moderátori: psichac, Moderátori
úprava programu
Zdravím. dá sa tento istý program spraviť aj bez toho aby som použil pointre? Program my ide ale s využitím pointrov (neviem ako fungujú neviem čo to je, našiel som si to na internete a skúšal upravovať až kým my to neišlo )
úloha je načítanie dvoch matic zo súboru a výpis. Načítanie rozmerov matice mám teda m a n.
int **maticaA;
maticaA = new int*[m];
for(int i = 0; i < m; i++) {
maticaA = new int[n];
for(int j = 0; j < n; j++){
insubor >> maticaA[j];
cout.width(2);
cout<<maticaA[j]<<"\t";
};
cout.endl;
}
úloha je načítanie dvoch matic zo súboru a výpis. Načítanie rozmerov matice mám teda m a n.
int **maticaA;
maticaA = new int*[m];
for(int i = 0; i < m; i++) {
maticaA = new int[n];
for(int j = 0; j < n; j++){
insubor >> maticaA[j];
cout.width(2);
cout<<maticaA[j]<<"\t";
};
cout.endl;
}
0
Re: úprava programu
Co tak pozriet si nieco o poliach?
0
“Nice looking” circuit construction doesn't always equate to good circuit performance.
http://www.arrl.org/files/file/Product% ... pter_1.pdf
Na predaj: p-bfx-predava-kto-zavaha-prerobi-t41148.html
http://www.arrl.org/files/file/Product% ... pter_1.pdf
Na predaj: p-bfx-predava-kto-zavaha-prerobi-t41148.html
Re: úprava programu
niečo o poliach viem
int maticaA[m][n]
for(int i = 0; i < m; i++) {
for(int j = 0; j < n; j++){
insubor >> maticaA[j];
cout.width(2);
cout<<maticaA[j]<<"\t";
};
cout.endl;
}
...slo byto?
int maticaA[m][n]
for(int i = 0; i < m; i++) {
for(int j = 0; j < n; j++){
insubor >> maticaA[j];
cout.width(2);
cout<<maticaA[j]<<"\t";
};
cout.endl;
}
...slo byto?
0
Re: úprava programu
Tak potom aky je problem prerobit to zo smernikov na matice?
0
“Nice looking” circuit construction doesn't always equate to good circuit performance.
http://www.arrl.org/files/file/Product% ... pter_1.pdf
Na predaj: p-bfx-predava-kto-zavaha-prerobi-t41148.html
http://www.arrl.org/files/file/Product% ... pter_1.pdf
Na predaj: p-bfx-predava-kto-zavaha-prerobi-t41148.html
Re: úprava programu
nesiel a skus zistit preco.
0
“Nice looking” circuit construction doesn't always equate to good circuit performance.
http://www.arrl.org/files/file/Product% ... pter_1.pdf
Na predaj: p-bfx-predava-kto-zavaha-prerobi-t41148.html
http://www.arrl.org/files/file/Product% ... pter_1.pdf
Na predaj: p-bfx-predava-kto-zavaha-prerobi-t41148.html
Re: úprava programu
Mohol by sa my nato niekto pozrieť---
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
void nacitajmaticuA (int **maticaA,int m,int n){
int klaA=0,zapA=0,parA=0,nepA=0;
ifstream insubor("C:\\Users\\JURO\\Desktop\\Zadanie\\vstup.txt");
ofstream outsubor("C:\\Users\\JURO\\Desktop\\Zadanie\\vystup.txt");
if (insubor. is_open()){
insubor >> m >> n;
cout<<"nacitana matica A"<<endl;
outsubor <<"nacitana matica A"<<endl;
maticaA = new int*[m];
for(int i = 0; i < m; i++) {
maticaA = new int[n];
for(int j = 0; j < n; j++){
insubor >> maticaA[j];
if (maticaA[j] >0) {klaA=klaA+1;}
else {zapA=zapA+1;}
if (abs(maticaA[j])%2==0) {parA=parA+1;}
else {nepA=nepA+1;}
cout.width(2);
cout<<maticaA[j]<<"\t";
outsubor .width(2);
outsubor <<maticaA[j]<<"\t";
};
outsubor <<endl;
cout<<endl;
}
}
}
int _tmain(int argc, _TCHAR* argv[])
{
ifstream insubor("C:\\Users\\JURO\\Desktop\\Zadanie\\vstup.txt");
int **maticaA;
int m;
int n;
insubor >> m >> n;
nacitajmaticuA(maticaA,m,n);
return 0;
}
Vyhadzuje chybu c4700 maticaA used
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
void nacitajmaticuA (int **maticaA,int m,int n){
int klaA=0,zapA=0,parA=0,nepA=0;
ifstream insubor("C:\\Users\\JURO\\Desktop\\Zadanie\\vstup.txt");
ofstream outsubor("C:\\Users\\JURO\\Desktop\\Zadanie\\vystup.txt");
if (insubor. is_open()){
insubor >> m >> n;
cout<<"nacitana matica A"<<endl;
outsubor <<"nacitana matica A"<<endl;
maticaA = new int*[m];
for(int i = 0; i < m; i++) {
maticaA = new int[n];
for(int j = 0; j < n; j++){
insubor >> maticaA[j];
if (maticaA[j] >0) {klaA=klaA+1;}
else {zapA=zapA+1;}
if (abs(maticaA[j])%2==0) {parA=parA+1;}
else {nepA=nepA+1;}
cout.width(2);
cout<<maticaA[j]<<"\t";
outsubor .width(2);
outsubor <<maticaA[j]<<"\t";
};
outsubor <<endl;
cout<<endl;
}
}
}
int _tmain(int argc, _TCHAR* argv[])
{
ifstream insubor("C:\\Users\\JURO\\Desktop\\Zadanie\\vstup.txt");
int **maticaA;
int m;
int n;
insubor >> m >> n;
nacitajmaticuA(maticaA,m,n);
return 0;
}
Vyhadzuje chybu c4700 maticaA used
0
Re: úprava programu
1.) ked sem vkladas kod, tak ho vkladaj do tagov [ code ] a naformatovany!
2.) ked sem pises aku chybu ti to pise, napis cele znenie! V tvojom pripade: error C4700: uninitialized local variable 'maticaA' used
3.) ked ti program napise chybu tak si ju precitaj!
Znenie chyby ti pise ze pouzivas neinicializovanu premennu. Ked ju chces inicializovat az vnutri vo funkcii, tak ju pri deklaracii inicializuj na null, tzn.:
2.) ked sem pises aku chybu ti to pise, napis cele znenie! V tvojom pripade: error C4700: uninitialized local variable 'maticaA' used
3.) ked ti program napise chybu tak si ju precitaj!
Znenie chyby ti pise ze pouzivas neinicializovanu premennu. Ked ju chces inicializovat az vnutri vo funkcii, tak ju pri deklaracii inicializuj na null, tzn.:
Kód: Vybrať všetko
int **maticaA = NULL;
0
Re: úprava programu
JuroOO napísal:Zdravím. dá sa tento istý program spraviť aj bez toho aby som použil pointre? Program my ide ale s využitím pointrov (neviem ako fungujú neviem čo to je, našiel som si to na internete a skúšal upravovať až kým my to neišlo )
úloha je načítanie dvoch matic zo súboru a výpis. Načítanie rozmerov matice mám teda m a n.
int **maticaA;
maticaA = new int*[m];
for(int i = 0; i < m; i++) {
maticaA = new int[n];
for(int j = 0; j < n; j++){
insubor >> maticaA[j];
cout.width(2);
cout<<maticaA[j]<<"\t";
};
cout.endl;
}
ano da sa len je to trochu zložitejšie ...
0
rad pomožem druhym, ak viem
-
- Podobné témy
- Odpovedí
- Zobrazení
- Posledný príspevok