开发者

error: too few arguments to function `void alpha(std::string*, student)'

Okay, I would like to explain what I am trying to do prior to the code with the issue. I am creating a student record system. I am trying to pull information from a text file into the record system. I am trying to store the information using arrays on a heap.

I am mostly concerned with the first few errors as I feel that those lead to the following ones. Any help would be greatly appreciated as I have looked through many forums and they have not lead me in the correct direction. Thanks in advance!

Code:

#include "address.h"
#include "student.h"
#include "date.h"
#include "record.h"
#include "name.h"

#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>

#define pArray
#define students
#define Request

using namespace :: std;



enum {sNUMBER=50};

//Function Prototypes
void tPrint(string*,student pArray);
void sPrint(string*,student pArray);
void alpha(string*,student pArray);
int generate();
//Function Definitions
void tPrint(string*,student pArray, alpha)
{
    if (alpha != 0)
    {
        alpha(pArray);
    }//end if
    int i;
    for (i=0; i<sNUMBER;i++)
    {
        pArray->tPrint();
        p开发者_开发问答Array+=1;
    }//end for
};//end tPrint
void sPrint(string*,student pArray)
{
    if (alpha != 0)
    {
        alpha(pArray);
    }//ennd if
    int i;
    for (i=0; i<sNUMBER;i++)
    {
        pArray->sPrint();
        pArray+=1;
    }//end for
};//end sPrint
void alpha(string*,student pArray)
{
    int i;//counter
    int j;//counter
    for (i=0;i<sNUMBER-1;i++)
    {
        for (j=0;j<sNUMBER-1-i;j++)
        {
            //combine first and last names into full names
            if (strcmp((pArray->GetsName().GetfName())+=" " +=(pArray->GetsName().GetlName()),((pArray+1)->GetsName().GetfName())+=" "+=((pArray+1)->GetsName().GetlName()))>0)
            {
                swap(pArray[j],pArray[j+1]);
            }
        }//end for
    }//end for
};//end alpha

int generate ()
{
    srand(sNUMBER);
    ofstream data;
    data.open ("data.txt");
    if (data.is_open())
    {
        int i; // counter
        int j; // counter

        //Name info
        string new fName[sNUMBER];
        string new lName[sNUMBER];
        //Address info
        string new add1[sNUMBER];
        string new add2[sNUMBER];

        //variables to generate names
        string new fName1[5] = {"Alfred","Robert","Ryan","Hank","Richard"};
        string new fName2[5] = {"Hannah","Lacie","Crystal","Kayce","Susan"};
        string new lName1[5] = {"Smith","Jones","Allison","Johnson","Moore"};
        string new lName2[5] = {"Howard","Williams","Pinkston","Cooley","Vernon"};
        string new fNames[2] = {fName1,fName2};
        string new lNames[2] = {lName1,lName2};

        // variables to generate addresses
        string new adds1[5] = {"159 faternity st.","399 Dorm Blvd.","222 faternity st.", "777 Dorm Blvd", "82 Canal street"};
        string new adds2[10] = {"Apartment A", "Apartment B", "Apartment C", "Apartment D", "Apartment E","Apartment F", "Apartment G", "Apartment H", "Apartment I"};

        for (i=0;i<sNUMBER;i++)
        {
            for (j=0; j<5; j++)
            {
                strCopy(fName[i],fNames[i>25][j]);
                strCopy(lName[i],lNames[i>25][j + floor(i/5)-(i>25)*(floor(i/5)-6)- 4*((j+i/5)>5)]);

            }
        }





        for (i=0;i<sNUMBER;i++)
        {
            for (j=0; j<10; j++)
            {
                strCopy(add1[i],adds1[j]);
                strCopy(add2[i],adds2[j + floor(i/10)-(i>25)*(floor(i/10)-11)- 4*((j+i/10)>10)]);

            }
        }


        //deallocate unneeded variables
        delete [] fName1;
        delete [] fName2;
        delete [] lName1;
        delete [] lName2;
        delete [] fNames;
        delete [] lNames;

        for (i=0; i<sNUMBER;i++)
        {
            // name info
            Data << fName[i] << "\n"; // first name
            Data << lName[i] << "\n"; // last name
            // address info
            Data << add1[i] <" \n"; // add 1
            Data << add2[i] <" \n"; // add 2
            Data << "Indianapolis  \n"; // city
            Data << "IN  \n"; // state
            Data << "46168 \n"; // zip
            // birthdate
            Data << rand()%28 + 1  << " \n"; //day

            Data << rand()%12 + 1 << " \n";//month
            Data << 2011 -(rand()%49 + 12)<< "\n";//year
            //graddate
            Data << rand()%28 + 1 << " \n";//day

            Data << rand()%12 + 1 << " \n"; // month
            Data << 2011 + (rand()%6+2)<< " \n"; // year
            //performance info
            Data << (rand()%16)/(float rand()%4)<<" \n"; //gpa
            Data << (rand()%300)<< " \n"; //credits

        }

        //Deallocate rest of memory
        delete [] fName;
        delete [] lName;
        delete [] add1;
        delete [] add2;


        data.close();
    }
    else
    {
        cout << "Your file did not open. Sorry \n";
    }
    return 0;
}//end generate}

Here are the errors:

C:\Users\main.cpp||In function ‘void tPrint(std::string*, student)’:|
C:\Users\main.cpp|25|error: too few arguments to function ‘void alpha(std::string*, student)’|
C:\Users\main.cpp|32|error: at this point in file|
C:\Users\main.cpp|37|error: expected primary-expression before ‘->’ token|


1) The three #defines in your code are probably just plain wrong

#define pArray
#define students
#define Request

Especially "pArray", since you use it as a parameter name later on.

2) You're comparing a function against zero. That doesn't make sense, since the test will always succeed.

if (alpha != 0)
{
    alpha(pArray);
}//end if

EDIT: Wait, I see, there's an (incorrectly declared) parameter "hiding" the global name "alpha". Well, that obviously cannot work either, since the parameter has no name ("alpha" is actually the type).

3) As already stated in a comment by David Thornley, you try to call the function with a single argument, which obviously cannot work, since you declared it with two arguments. (Actually you call it with no arguments at all, since the pArray #define will be "expanded" to empty-string)

4) The syntax you try to use to declare variables is just plain wrong

string new fName[sNUMBER];

I do not even know what that is supposed to mean.

And there is probably so much more...


You really need to get a tutorial or introductory text on C++. There are so many things wrong that I wouldn't know where to begin... the #define's in the beginning of the file make no sense (what do you intend with that? the real effect is that the preprocessor will discard those words), you should not handle strings through pointers (pass references, if possible constant references), you are declaring a tPrint function with two arguments, and defining a different tPrint overload with three, the last of which is incorrect, as alpha is not a type. The first and second argument (after preprocessor substitutions) are unnamed so they cannot be used...

And all that before getting to the first actual line of code...


The error is: too few arguments to function void alpha(std::string*, student). When we lookup in the code you typed:alpha(pArray);. But the function signature is: void alpha(string*,student pArray);

So pass a string as parameter will fix the error but there there are a lot of other wrong things in your code:

  • void tPrint(string*,student pArray, alpha) What is alpha? I only see an empty define
  • string new fName[sNUMBER]; Wont compile. I think you mean string* name = new fName[sNUMBER]; And what is a fName?
  • Many more strange things...

Maybe a C++ tutorial fits you better: see here


Your big problem is the #defines. What you are doing with those is defining the identifiers as, literally, nothing. Where there was a pArray, there is now nothing. In C++, any line beginning with # is a preprocessor command, meaning it operates on the text of the program. In order to actually define an identifier, you just, essentially describe it.

You are using pArray as function parameters, which means none of its occurrences are at the outer scope. If the preprocessor behaved like any other part of C++, then, it would be harmless, but it just does textual substitution. You might want to let the compiler tell you when you have failed to define something.

Another issue is the "too few arguments". You declare alpha as taking two arguments, but only pass one when you call it early in tPrint.

I'm not going to go through the rest of the errors until you fix what you've got. Once you've removed the #defines and read through the other errors yourself.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜