my first.h:
class skaiciavimas
{
public:
vector<int> vekto[2];
skaiciavimas();
~skaiciavimas();
....
my first.cpp
#include "skaiciavimas.h"
skaiciavimas::skaiciavimas()
{ int i;
for(i=0;i<2;i++)
vekto[i].resize(3);
}
void skaiciavimas::showst(vector<int> st,int i)
{
vekto[i].at(0)=st.at(0);
vekto[i].at(1)=st.at(1);
vekto[i].at(2)=st.at(2);
cout<<vekto[1].at(0)<<vekto[0].at(0)<<endl;
}
void skaiciavimas::tikrinimas ()
{
cout<<vekto[1].at(0)<<vekto[0].at(0)<<endl;// gives always 0,0
....
there is second class from where i call shwst function
second.cpp:
vandenynas::vandenynas()
{
vektorV.resize(3);
}
void vandenynas::duomenys (int i, int a, int a0)
{
switch (i)
{
case 0:
vektorV.at(0)=a-a0;
break;
case 1:
vektorV.at(1)=a-a0;
break;
default:
vektorV.at(2)=a-a0;
break;
}
sk.showst(vektorV,0);
}
the tikrinimas function i call from my main:
sk.tikrinimas();
why this line
cout<<vekto[1].at(0)<<vekto[0].at(0)<<endl;
alvays gives me 00, how to correct that to get the rigt numbers wich were assign in showst
P.S sk is my class (first sk;)
there is called duomenys and tikrinimas :
vandenynas vand;
skaiciavimas sk;
int main()
{
int i,a,a0,t;
int j=1;
while (j<3)
{
for (i=0;i<3;i++)
{
cout<<"enter "<<kas<<kint(i)<<" kordinates"<<endl;
cout<<kint(i)<<"0 = ";
cin>>a0;
cout<<kint(i)<<" = ";
cin>>a;
cout<<endl;
if (j==1)
vand.duomenys(i,a,a0);
}
j++;
}
sk.tikrinimas();
...
You read the input into local variables, but never call
sk.showstwith those values. It shouldn’t be surprising that it’s members are still whatever the defaults are.