Ask your own question, for FREE!
Computer Science 9 Online
OpenStudy (anonymous):

how to Transfer/Array ???

OpenStudy (anonymous):

OpenStudy (anonymous):

@Callisto help me mamen ... :D

OpenStudy (callisto):

int arr[rows][columns] = {{entries in first row}, {entries in second row}, ... {entries in the last row}};

OpenStudy (callisto):

for all 0's entries, if I remember correctly, you just need {0} for the initialization.

OpenStudy (callisto):

Maybe you should try the transfer part first.

OpenStudy (anonymous):

yeah its always start at 0

OpenStudy (anonymous):

yeah i need to transfer it..

OpenStudy (anonymous):

but the questin is how??

OpenStudy (callisto):

Have you tried?

OpenStudy (anonymous):

im now trying to answer...

OpenStudy (callisto):

When you do the transfer, you probably need a temp array.

OpenStudy (anonymous):

i just need a guide to answer it...

OpenStudy (callisto):

Ok, tell me what you have got.

OpenStudy (anonymous):

thats for the transfer

OpenStudy (anonymous):

for (a=0; a<5; a++) { cin>>Array[a]; } for (b=0;b<4;b++) { for (int c=0;c<4-b;b++) { if (Array[c]>Array[c+1]) { temp=Array[c]; Array[c]=Array[c+1]; Array[c+1]=temp; } } }

OpenStudy (callisto):

Post the whole programme here: http://pastebin.com/ Post the link here again after you post the code here

OpenStudy (anonymous):

ok

OpenStudy (anonymous):

http://pastebin.com/cSvtU5MP

OpenStudy (callisto):

I really need to read the WHOLE programme, or else, add comments in your code. I don't even know which array is storing what values.

OpenStudy (anonymous):

ok... wait

OpenStudy (anonymous):

here's my answer but im not sure.. http://pastebin.com/FJ2MNY4F

OpenStudy (callisto):

Sorry, you need not use a temp array...

OpenStudy (anonymous):

ok .. what should i do??

OpenStudy (callisto):

Your code looks so complicated as well. Here's what I've got. http://pastebin.com/nzGe8sTW

OpenStudy (anonymous):

thank you Callisto ^_^

OpenStudy (anonymous):

hahah

OpenStudy (callisto):

When you print an 2D array, you need a nested for-loop (for loop inside a for-loop)

OpenStudy (anonymous):

uhh

OpenStudy (callisto):

I don't see why you need a if-else statement there as well.

OpenStudy (anonymous):

hehehh sorry

OpenStudy (callisto):

It's ok.. By the way, I just realized that I did something silly in my code. You may want to improve that code I posted. Big thanks to @experimentX for spotting it out :)

OpenStudy (anonymous):

hehehe thank you @experimentX ^_^

OpenStudy (experimentx):

yw ... both of you. it's better to write a module to print the content of arrays ... since you need to repeat it 4 times.

OpenStudy (anonymous):

uhhh

OpenStudy (anonymous):

@Callisto i have some question ...... :D

OpenStudy (anonymous):

can you help me @Callisto ??

OpenStudy (callisto):

?

OpenStudy (anonymous):

what statement should i change in the Transfer if i change the 10 1 9 2 8 3 7 4 6 5 to 1 2 3 4 5 6 7 8 9 10

OpenStudy (callisto):

Your guess?

OpenStudy (anonymous):

like this

OpenStudy (anonymous):

i observe that it counts from left to right and it is increasing

OpenStudy (callisto):

And what have you got for this question so far?

OpenStudy (anonymous):

what statement should i put in the program to display 1 2 3 4 5 6 7 8 9 10

OpenStudy (callisto):

Just to display this?

OpenStudy (callisto):

Use a nested for loop to do it.

OpenStudy (anonymous):

or the statement to change the //transfer

OpenStudy (anonymous):

to display that

OpenStudy (callisto):

Show me your program.

OpenStudy (anonymous):

http://pastebin.com/nzGe8sTW

OpenStudy (anonymous):

remember??

OpenStudy (anonymous):

but that already correct but we need to change the //transfer to get the 1 2 3 4 5 6 7 8 9 10

OpenStudy (anonymous):

//transfer for(int i=0; i<5; i++){ arr2[i][0] = arr1[1][i]; } for(int i=0; i<5; i++){ arr2[i][1] = arr1[0][i]; }

OpenStudy (anonymous):

we need to make new one in that part..

OpenStudy (callisto):

So what have you tried?

OpenStudy (anonymous):

yeah i tried but so far

OpenStudy (callisto):

Show me what you have got then.

OpenStudy (anonymous):

int a; //transfer for(int i=0; i<5; i++){ if arr2[a][0]= arr1[1][i]; a++

OpenStudy (anonymous):

i dont know... hehehe

OpenStudy (anonymous):

wait

OpenStudy (anonymous):

the table is like this right?? 00 01 10 11 20 21 30 31 40 41

OpenStudy (anonymous):

int a; //transfer for(int row=0; row<2; row++){ for(int col=0; col<5; col++){ if arr2[row][0]= arr1[1][col];

OpenStudy (anonymous):

@Callisto

OpenStudy (callisto):

What are you doing in this piece of code? //transfer for(int row=0; row<2; row++){ for(int col=0; col<5; col++){ if arr2[row][0]= arr1[1][col];

OpenStudy (anonymous):

sorry

OpenStudy (callisto):

Find a paper, write the the output with that piece of code, you'll know what you were doing.

OpenStudy (anonymous):

#include<iostream> using namespace std; int main() { int arr1[2][5]={{1,2,3,4,5}, {10,9,8,7,6}}; int arr2[5][2]={0}; int i; //print the first array for(int i=0; i<2; i++){ for(int j=0; j<5; j++){ cout << arr1[i][j] << " "; } cout << endl; } cout << endl; //print the second array for(int i=0; i<5; i++){ for(int j=0; j<2; j++){ cout << arr2[i][j] << " "; } cout << endl; } cout << "\nAfter transfer... \n" << endl; //transfer the entry in array 1 to array 2. for(int row=0; row<5; row++){ for( col==0) if arr2[row][col]= arr1[row][i]; } i++ } return 0;

OpenStudy (callisto):

Have you compiled the programme?

OpenStudy (callisto):

for(int row=0; row<5; row++){ for( col==0) if arr2[row][col]= arr1[row][i]; <--- what is this line doing? i++ }

OpenStudy (anonymous):

OpenStudy (anonymous):

#include<iostream> using namespace std; int main() { int arr1[2][5]={{1,2,3,4,5}, {10,9,8,7,6}}; int arr2[5][2]={0}; int a; //print the first array for(int i=0; i<2; i++){ for(int j=0; j<5; j++){ cout << arr1[i][j] << " "; } cout << endl; } cout << endl; //print the second array for(int i=0; i<5; i++){ for(int j=0; j<2; j++){ cout << arr2[i][j] << " "; } cout << endl; } cout << "\nAfter transfer... \n" << endl; //transfer the entry in array 1 to array 2. for(int row=0; row<5; row++){ for( col==0) if arr2[row][col]= arr2[row][a]; else arr1[1][a]=arr1[0][a]; a++ }

OpenStudy (callisto):

if-else is a conditional statement... if (something) do something here if it is true else do something here if it is false

OpenStudy (callisto):

Example: int x = 1; if (x == 1) cout << "cheers" << endl; // print "cheers" if x = 1 else cout << "NO" << endl; // print "NO" if x is not equal to 1

OpenStudy (anonymous):

uhh

OpenStudy (anonymous):

//transfer the entry in array 1 to array 2. for(int row=0; row<5; row++){ for( col==0) if arr2[row][col]= arr2[row][a]; if arr1[1][a]=arr1[0][a]; a++ } can i make it like this??

OpenStudy (callisto):

Of course you can't.

OpenStudy (anonymous):

OpenStudy (anonymous):

aww

OpenStudy (anonymous):

hhehehe

OpenStudy (callisto):

Have you revised before you do the programming exercises? My advice is that you'd better revise before you carry on.

OpenStudy (anonymous):

no

OpenStudy (anonymous):

??

OpenStudy (anonymous):

#include<iostream> #include<iomanip> using namespace std; void main(){ int arr1[2][5]={{1,2,3,4,5},{10,9,8,7,6}}; int arr2[5][2]={0}; int x, y; cout<<"Array 1"<<endl; for(x=0;x<2;x++){ for(y=0;y<5;y++){ cout<<setw(2)<<arr1[x][y];} cout<<endl;} cout<<endl<<"Array 2:"<<endl; for(x=0;x<5;x++){ for(y=0;y<2;y++){ cout<<setw(2)<<arr2[x][y]<<" ";} cout<<endl;} for(x=0;x<2;x++){ for(y=0;y<5;y++){ if(x==1){ arr2[y][0]=arr1[x][y];} else if(x==0){ arr2[y][1]=arr1[x][y];} } cout<<endl<<"After Array Manipulation:"<<endl; cout<<endl<<"Array 1"<<endl; for(x=0;x<2;x++){ for(y=0;y<5;y++){ cout<<setw(2)<<arr1[x][y]<<" ";} cout<<endl;} cout<<endl<<"Array 2:"<<endl; for(x=0;x<5;x++){ for(y=0;y<2;y++){ cout<<setw(2)<<arr2[x][y]<<" ";} cout<<endl;} }

OpenStudy (anonymous):

revise??

OpenStudy (callisto):

Revise = study.

OpenStudy (callisto):

What are you trying to do in the new code?

OpenStudy (anonymous):

yeah i need a new code on the part of Transfer..

OpenStudy (callisto):

Ok, you edit my code and here is what you got after your edition to my code: Array 1 1 2 3 4 5 10 9 8 7 6 Array 2: 0 0 0 0 0 0 0 0 0 0 After Array Manipulation: Array 1 1 2 3 4 5 10 9 8 7 6 Array 2: 0 1 0 2 0 3 0 4 0 5

OpenStudy (anonymous):

aww still i dont got the right answer :/

OpenStudy (callisto):

Do you know what the function setw(int n) does?

OpenStudy (anonymous):

int n is infinite?? its also it defend to user until when to end

OpenStudy (anonymous):

joke.. i dont know

OpenStudy (callisto):

But you added that function to your code.

OpenStudy (callisto):

http://pastebin.com/M3MRBEhm

OpenStudy (callisto):

If you don't try to write it yourself, you can never write it.

OpenStudy (anonymous):

okok

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!