Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am completely lost when it comes to these 4 questions someone please help. I r

ID: 1847409 • Letter: I

Question

I am completely lost when it comes to these 4 questions someone please help. I really need the credit for these problems and to be able to answer them on the next test

33.)

Given the following function prototype

int strcmp(char[],char[]);

Write just the function definition. The function returns 0 when the two arrays contain the same thing. Otherwise the function returns the same position in the array where the values differ. The position will be negative when the first parameter is<second parameter and positive when the second parameter < first parameter. The last position to compare in each array contains a null character ().



34.) Write the prototype for a class that represents cars. The only attributes are mpg(double) and horsepower(int). There is one constructor with no parameters and a destructor. The only methods are get and set functions for each two of the attributes (four total methods). Do not use any inline functions.


35.) Write a class definition(class.cpp file) for the class you defined above. The constructor should initialize values to to -1 and the destructor should display the message "Goodbye"


36.) Write a simple main function to 1.) declare a variable using the class you defined above, 2.) set the values to be 27.9 MPG and 352 HP and 3.) display the values using the get functions.



I would really love some help with these. More than you know. Thanks in advance to anyone willing to help me out.

Explanation / Answer

33 ) #include <iostream>

using namespace std;

int strcmp(char a[], char b[])
{
    int compared = 0;
    int lengtha = 0, lengthb = 0;
    for(int i = 0; a[i] != ''; i++)
        lengtha++;
    for(int i = 0; b[i] != ''; i++)
        lengthb++;
    if(lengtha < lengthb)
    {
        for(int i = 0; i < lengtha; i++)
        {
            if(a[i]!=b[i])
                return -i;
        }
        return -lengtha;
       
    }
    else if(lengtha > lengthb)
    {
        for(int i = 0; i < lengtha; i++)
        {
            if(a[i]!=b[i])
                return i;
        }
        return -lengtha;
    }
    else
    {
        for(int i = 0; i < lengtha; i++)
        {
            if(a[i]!=b[i])
                return i;
        }
        return 0;
    }
}

int main()
{
    cout << strcmp("abc", "abcd") << endl;
    cout << strcmp("abcd", "abc") << endl;
    cout << strcmp("abcd", "abcd") << endl;
    return 0;

}


34, 35, 36)

#include <iostream>

using namespace std;

class cars
{
private:
    double mpg;
    int horsepower;
public:
    cars(void);
    void setmpgval(double);
    void sethpval(int);
    int gethpval();
    double getmpgval();
    ~cars();

};

cars::cars()
{
    mpg = 0.0;
    horsepower = 0;
}

void cars::setmpgval(double mpgval)
{
    mpg = mpgval;
}

void cars::sethpval(int hpval)
{
    horsepower = hpval;
}

int cars::gethpval()
{
    return horsepower;
}

double cars::getmpgval()
{
    return mpg;
}

cars::~cars(){}

int main()
{
    cars a;
    a.sethpval(352);
    a.setmpgval(27.9);
    cout << "Hp" << a.gethpval() << endl;
    cout << "Mpg" << a.getmpgval() << endl;
    a.~cars();
    return 0;
}