首先发布在这里。我正在创建一个按字母顺序对数组进行排序的程序,并显示未排序和排序的列表。但是,当通过Lab5.cpp测试排序函数时,它声明在标头中声明的数组指针和实现.cpp是未声明的,尽管原型匹配实际的函数调用。我发布了一个mediafire链接,如果需要,我可以发布文本。
http://www.mediafire.com/?39xfxm3canjndte
//Lab 5.cpp
#include <iostream>
#include <string>
#include <iomanip>
#include "Student.h"
using namespace std;
int main()
{
Student stu;
stu.getStudent();
stu.displayStudent();
stu.sortStudent(string *nameArray[], int *ageArray[]);
system("pause");
};
//Student.h
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
class Student
{
public:
Student();
void setStudent();
int getStudent();
int sortStudent(string *nameArray[], int *ageArray[]);
void displayStudent();
void displaySorted(string *nameArray[], int *ageArray);
private:
string names[50];
int age[50];
int size;
};
//Student.cpp
using namespace std;
#include <iostream>
#include <string>
#include "Student.h"
Student::Student()
{
setStudent();
};
void Student::setStudent()
{
for(int i = 0; i <= size; i++)
{
age[i] = 0;
}
};
int Student::getStudent()
{
string temp;
cout << "Enter number of people <0 . . 50>" << endl << "> ";
cin >> size;
getline( cin, temp);
for(int i = 1; i <= size; i++)
{
cout << "Enter name " << i << " (lastname, firstname): ";
getline( cin, names[i] );
cout << "Enter age " << i << ": ";
cin >> age[i];
cout << endl;
getline( cin, temp );
}
};
int Student::sortStudent(string *nameArray[], int *ageArray[])
{
*nameArray[i] = &name[i];
*ageArray[i] = &age[i];
};
void Student::displayStudent()
{
cout << "Original list" << endl;
cout << "------------------------" << endl;
for(int i = 1; i <= size; i++)
{
cout << names[i] << setw(28) << age[i] << endl;
}
};
void Student::displaySorted(string *nameArray[], int *ageArray)
{
};
答案 0 :(得分:0)
我认为您需要实现所需的sortStudent方法和displayStudent方法。
好的,让我们从
开始 1. Tagging this as homework and c++
2. Give a print out of the error
~/Desktop/test/Student$ make
g++ -c Student.cpp -o Student.o -I.
g++ -c Lab5.cpp -o Lab5.o -I.
Lab5.cpp: In function ‘int main()’:
Lab5.cpp:14: error: expected primary-expression before ‘*’ token
Lab5.cpp:14: error: ‘nameArray’ was not declared in this scope
Lab5.cpp:14: error: expected primary-expression before ‘]’ token
Lab5.cpp:14: error: expected primary-expression before ‘int’
Lab5.cpp:15: error: ‘system’ was not declared in this scope
make: *** [Lab5.o] Error 1
3. Explain what you have tried, and what you are trying to do.
在我看来,你要实现这些方法: int sortStudent(string * nameArray [],int * ageArray []); void displaySorted(string * nameArray [],int * ageArray);
这会让某人快速指出错误并得到你
在你的路上。我相信错误是由于您需要更换
main()
函数中的函数存根,具有有效的函数调用。也,
如果这已被标记为c
或c++
,那么它可能会被评为
关。所以,最后,希望这有助于阅读SO FAQ。