Bubble Sort?

So ive been working on this program for five hours now and i trying to sort this array of student names with their test scores. this is what i have

#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <cstring>
using namespace std;

void getData(int size, int [], char [][6]);
void sortData(char [][6], int);

void main(){
int scores[5];
char students [5][6];
int size;

cout << "Enter size for arrays: ";
cin >> size;
getData(size,scores,students);

cout << "ARRAYS BEFORE SORTING" << endl;
for (int i = 0; i < 5; i++)
cout << students[i] << endl;
sortData(students, 5);

cout << "ARRAYS AFTER SORTING :" << endl;
for (int i = 0; i < 5; i++)
cout << students[i] << endl;
// end for





}

void getData(int size, int testScore[],char studentName[][6]) {

int index;

for (index = 0; index <= size -1; index++){
cout << "Enter " <<(index +1) << "th student name: "
<< ": ";
cin >> studentName[index];
cout << "Enter test score for " << studentName[index]
<< ": ";
cin >> testScore[index];

while (0 > testScore[index] || testScore[index] > 100){
cout << "Re-enter test score for " << studentName[index]
<< ": ";
cin >> testScore[index];

}// end while
}// end for

}

void sortData(int size, char studentName[][6]){
bool swap;
int temp[6];

do {
swap = false;
for (int count = 0; count < (size - 1); count++) {
if (strcmp(studentName[count], studentName[count+1]) > 0) {
strcpy_s(temp, studentName[count]);
strcpy_s(studentName[count], studentName[count+1]);
strcpy_s(studentName[count+1], temp);
swap = true;
} // end if
} // end for
} while (swap);

}

i get these errors:
error C2660: 'strcpy_s' : function does not take 2 arguments
error C2665: 'strcpy_s' : none of the 2 overloads could convert all the argument types c:\program files (x86)\microsoft visual studio 10.0\vc\include\string.h(104): could be 'errno_t strcpy_s<6>(char (&)[6],const char *) throw()' while trying to match the argument list '(char [6], int [6])'

please help!
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <cstring>
using namespace std;

void getData(int size, int [], char [][6]);
void sortData(char [][6], int);
void printData(char [][6], int);

void main(){
int scores[5];
char students[5][6];
int size;

cout << "Enter size for arrays: ";
cin >> size;
getData(size,scores,students);

cout << "ARRAYS BEFORE SORTING" << endl;
for (int i = 0; i < 5; i++)
cout << students[i] << endl;
sortData(students, 5);

cout << "ARRAYS AFTER SORTING :" << endl;
for (int i = 0; i < 5; i++)
cout << students[i] << endl;
// end for

}

void getData(int size, int testScore[],char studentName[][6]) {

int index;

for (index = 0; index <= size -1; index++){
cout << "Enter " <<(index +1) << "th student name: "
<< ": ";
cin >> studentName[index];
cout << "Enter test score for " << studentName[index]
<< ": ";
cin >> testScore[index];

while (0 > testScore[index] || testScore[index] > 100){
cout << "Re-enter test score for " << studentName[index]
<< ": ";
cin >> testScore[index];

}// end while
}// end for

}

void sortData(int size, char studentName[][6]){
bool swap;
char temp[6];

do {
swap = false;
for (int count = 0; count < (size - 1); count++) {
if (strcmp(studentName[count], studentName[count+1]) > 0) {
strcpy_s(temp, studentName[count]);
strcpy_s(studentName[count], studentName[count+1]);
strcpy_s(studentName[count+1], temp);
swap = true;
} // end if
} // end for
} while (swap);

}

made a few changes. now i get these errors
error LNK2019: unresolved external symbol "void __cdecl sortData(char (* const)[6],int)" (?sortData@@YAXQAY05DH@Z) referenced in function _main
fatal error LNK1120: 1 unresolved externals
Can someone plz help me!
In the definition of sortData you have switch the order of the parameters.
Thats not it
Are you sure? Maybe I was unclear. If you compare the declaration

void sortData(char [][6], int);

to the definition

void sortData(int size, char studentName[][6])

you see that they are not the same.
Last edited on
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <cstring>
using namespace std;

void getData(int size, int [], char [][6]);
void sortData(char [][6], int[], int);
void printData(char [][6], int);

void main(){
int scores[5];
char students[5][6];
int size;

cout << "Enter size for arrays: ";
cin >> size;
getData(size,scores,students);

sortData(students, scores, 5);



}

void getData(int size, int testScore[],char studentName[][6]) {

int index;

for (index = 0; index <= size -1; index++){
cout << "Enter " <<(index +1) << "th student name: "
<< ": ";
cin >> studentName[index];
cout << "Enter test score for " << studentName[index]
<< ": ";
cin >> testScore[index];

while (0 > testScore[index] || testScore[index] > 100){
cout << "Re-enter test score for " << studentName[index]
<< ": ";
cin >> testScore[index];

}// end while
}// end for

}

void sortData(char studentName[][6],int testScore[],int size){
bool swap;
char temp[6];

do {
swap = false;
for (int count = 0; count < (size - 1); count++) {
if (strcmp(studentName[count], studentName[count+1]) > 0) {
strcpy_s(temp,6, studentName[count]);
strcpy_s(studentName[count],6, studentName[count+1]);
strcpy_s(studentName[count+1],6, temp);
swap = true;
} // end if
} // end for
} while (swap);

}

there we go i got it now.
do you think you can help me print the data by using a printData function
I'm not going to write that function for you. If you have questions just post them here and someone will try to answer them.
alright ill try just to let u know iive been working on this since 3:30 and i still have a math exam to study for.

#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <cstring>
using namespace std;

void getData(int size, int [], char [][6]);
void sortData(char [][6], int[], int);
void printData(char [][6], int[]);

void main(){
int scores[5];
char students[5][6];
int size;

cout << "Enter size for arrays: ";
cin >> size;
getData(size,scores,students);

sortData(students, scores, 5);

printData(students,scores);



}

void getData(int size, int testScore[],char studentName[][6]) {

int index;

for (index = 0; index <= size -1; index++){
cout << "Enter " <<(index +1) << "th student name: "
<< ": ";
cin >> studentName[index];
cout << "Enter test score for " << studentName[index]
<< ": ";
cin >> testScore[index];

while (0 > testScore[index] || testScore[index] > 100){
cout << "Re-enter test score for " << studentName[index]
<< ": ";
cin >> testScore[index];

}// end while
}// end for

}

void sortData(char studentName[][6],int testScore[],int size){
bool swap;
char temp[6];

do {
swap = false;
for (int count = 0; count < (size - 1); count++) {
if (strcmp(studentName[count], studentName[count+1]) > 0) {
strcpy_s(temp,6, studentName[count]);
strcpy_s(studentName[count],6, studentName[count+1]);
strcpy_s(studentName[count+1],6, temp);
swap = true;
} // end if
} // end for
} while (swap);


}

void printData(char studentName[][6], int testScores[]){

cout << "ARRAYS BEFORE SORTING" << endl;
for (int i = 0; i < 5; i++)
cout << studentName[i] << endl;

cout << "ARRAYS AFTER SORTING :" << endl;
for (int i = 0; i < 5; i++)
cout << studentName[i] << endl;

int ok;
cin >> ok;

}

i got this now
it only sorts the names idk how to sort the names with the scores.
void printData(char studentName[][6], int testScores[]){

cout << "ARRAYS BEFORE SORTING" << endl;
cout << "NAME" << "\t\t" << "SCORE" << endl;
for (int i = 0; i < 5; i++)
cout << studentName[i] << endl;
cout << static_cast<int>(testScores[i]) << endl;

cout << "ARRAYS AFTER SORTING :" << endl;
cout << "NAME" << "\t\t" << "SCORE" << endl;
for (int i = 0; i < 5; i++)
cout << studentName[i] << endl;

int ok;
cin >> ok;

}

still not working
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <cstring>
using namespace std;

void getData(int size, int [], char [][6]);
void sortData(char [][6], int[], int);
void printData(char [][6], int[]);

void main(){
int scores[5];
char students[5][6];
int size;

cout << "Enter size for arrays: ";
cin >> size;
getData(size,scores,students);

sortData(students, scores, 5);

printData(students,scores);



}

void getData(int size, int testScore[],char studentName[][6]) {

int index;

for (index = 0; index <= size -1; index++){
cout << "Enter " <<(index +1) << "th student name: "
<< ": ";
cin >> studentName[index];
cout << "Enter test score for " << studentName[index]
<< ": ";
cin >> testScore[index];

while (0 > testScore[index] || testScore[index] > 100){
cout << "Re-enter test score for " << studentName[index]
<< ": ";
cin >> testScore[index];

}// end while
}// end for

}

void sortData(char studentName[][6],int testScore[],int size){
bool swap;
char temp[6];

do {
swap = false;
for (int count = 0; count < (size - 1); count++) {
if (strcmp(studentName[count], studentName[count+1]) > 0) {
strcpy_s(temp,6, studentName[count]);
strcpy_s(studentName[count],6, studentName[count+1]);
strcpy_s(studentName[count+1],6, temp);
swap = true;
} // end if
} // end for
} while (swap);


}

void printData(char studentName[][6], int testScores[]){

cout << "ARRAYS BEFORE SORTING" << endl;
cout << "NAME" << "\t\t" << "SCORE" << endl;
for (int i = 0; i < 5; i++)
cout << studentName[i] << "\t\t" << static_cast<int>(testScores[i]) << endl;

cout << "ARRAYS AFTER SORTING :" << endl;
cout << "NAME" << "\t\t" << "SCORE" << endl;
for (int i = 0; i < 5; i++)
cout << studentName[i] << "\t\t" << static_cast<int>(testScores[i]) << endl;

int ok;
cin >> ok;

}

i got it but it sorts both of them. how do i sort only the last one?
i got it now. thanks for the hlep
Topic archived. No new replies allowed.