using two-dimension Array in the class
Jun 1, 2016 at 2:24pm UTC
Hello,
I'm writing code students GradeBook
in main i have created two-dimension array
and passing it to void studentas::isvestiMasyva() function
but something is wrong because
I've got like this
Dalykas (1) 46664886 46664886 46664886
Dalykas (2) 46664886 46664886 46664886
Dalykas (3) 46664886 46664886 46664886
what I'm doing wrong?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
#include <iostream>
#include <string>
#include <iomanip>
#include <cstdlib>
using namespace std;
class studentas
{
public :
static const int PAZYMIS = 3;
static const int DALYKAS = 3;
//studentas() {}
studentas(int [DALYKAS][PAZYMIS]);
void isvestiMasyva();
private :
int masyvasPaz[DALYKAS][PAZYMIS];
};
studentas::studentas(int masyvas[DALYKAS][PAZYMIS])
{
for (int dal = 0; dal < DALYKAS; dal++)
for (int paz = 0; paz < PAZYMIS; paz++)
masyvasPaz[dal][paz] = masyvas[dal][paz];
}
void studentas::isvestiMasyva()
{
for (int dal = 0; dal < DALYKAS; dal++)
{cout << "Dalykas " << setw(3) << "(" << dal + 1 << ")" ;
for (int test = 0; test < PAZYMIS; ++test)
cout << setw(8) << /*(rand()%10);// <<*/ masyvasPaz[DALYKAS][PAZYMIS] ;
cout<<endl;}
}
int main()
{
//studentas s1;
int masyvasPazimiu[studentas::DALYKAS][studentas::PAZYMIS]
{ {5,6,8},
{8,6,9},
{10,5,6} };
studentas pazymiai(masyvasPazimiu);
pazymiai.isvestiMasyva();
}
Jun 1, 2016 at 4:55pm UTC
First off, you have a compile error. line 47 is missing an =.
Line 39: You're trying to print an element using the defined dimensions of the array, not the indexes to the array. Line 39 should be:
1 2 3 4
cout << setw(8) << /*(rand()%10);// <<*/ masyvasPaz[dal ][test ] ;
Dalykas (1) 5 6 8
Dalykas (2) 8 6 9
Dalykas (3) 10 5 6
Press any key to continue . . .
Last edited on Jun 1, 2016 at 4:56pm UTC
Topic archived. No new replies allowed.