How to use a class object in C++ as a function parameter

后端 未结 5 1898
离开以前
离开以前 2021-01-30 07:15

I am not sure how to have a function that receives a class object as a parameter. Any help? Here is an example below.

#include

void function(cla         


        
5条回答
  •  梦如初夏
    2021-01-30 07:56

    holy errors The reason for the code below is to show how to not void main every function and not to type return; for functions...... instead push everything into the sediment for which is the print function prototype... if you need to use useful functions ... you will have to below..... (p.s. this below is for people overwhelmed by these object and T templates which allow different variable declaration types(such as float and char) to use the same passed by value in a user defined function)

    char arr[ ] = "This is a test";
    
    string str(arr);
    
    
    //  You can also assign directly to a string.
    str = "This is another string";
    

    can anyone tell me why c++ made arrays into pass by value one at a time and the only way to eliminate spaces and punctuation is the use of string tokens. I couldn't get around the problem when i was trying to delete spaces for a palindrome...

    #include 
    #include 
    using namespace std;
    int getgrades(float[]);
    int getaverage(float[], float);
    int calculateletters(float[], float, float, float[]);
    int printResults(float[], float, float, float[]);
    
    
    int main()
    {
    
    int i;
    float  maxSize=3, size;
    float  lettergrades[5], numericgrades[100], average;
    
    size=getgrades(numericgrades);
    average = getaverage(numericgrades, size);
    printResults(numericgrades, size, average, lettergrades);
    return 0;
    }
    
    int getgrades(float a[])
    { 
    
    
    int i, max=3;
    
    for (i = 0; i > a[i];
        //makes sure that user enters a vlue between 0 and 100
    
       if(a[i] < 0 || a[i] >100)
        {
            cout << "Wrong input. Please
     enter a value between 0 and 100 only." << endl;
            cout << "\nPlease Reenter grade " << i+1 << " : ";
            cin >> a[i];
    
            return i;
        }
    }
    }
    
    int getaverage(float a[], float n) 
    { 
    int i;
    float sum = 0;
     if (n == 0)
    return 0;
    for (i = 0; i < n; i++)
    sum += a[i];
    return sum / n;
    }                               
    
    
    int printResults(float a[], float n, float average, float letters[]) 
    {
    int i;
    cout << "Index Number | input  |
    array values address in memory " << endl;
    
    for (i = 0; i < 3; i++)
    {
    cout <<"     "<< i<<" \t\t"<

提交回复
热议问题