We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

- Prepare
- C++
- Classes
- Classes and Objects
- Discussions

# Classes and Objects

# Classes and Objects

+ 0 comments What is difference between object class and class? https://bit.ly/3AYD6RU

+ 0 comments Here are the solution of [Classes and Objects Hacker Rank Solution] https://www.chase2learn.com/classes-and-objects-hacker-rank-solution/

+ 0 comments `Create a class named Vector with four (integer) data members (x and y coordinates of two points). Provide default and parameterized constructors. Provide a set method which accepts four integers and sets the values of the data members. Provide get() methods to return each of the data members. Provide functions to calculate the magnitude and direction of the vector. In main(), declare an object v1 of class vector, call the functions to compute the magnitude and direction of the vector and display these values in the main. Declare another object v2 of vector and set its data members. Compute the dot product between v1 and v2. ((v1) ⃗.(v2) ⃗=v1.x*v2.x+v1.y*v2.y) Compute the angle between the two vectors. (Hint:(v1) ⃗.(v2) ⃗= |v1||v2|cosθ) Compute the magnitude of the cross product of the two vectors. (Hint: |v1||v2|sinθ)`

+ 0 comments class Student { static const int NUM_SCORES = 5; int scores[NUM_SCORES]; public: void input() { for (int i= 0; i < NUM_SCORES && cin >> scores[i]; i++); } int calculateTotalScore() const { int sum = 0, i = NUM_SCORES - 1; for( ; i >= 0; sum += scores[i--] ); return sum; } };

+ 0 comments C++

class Student { public: Student(); void input(); int calculateTotalScore(); private: int score[5]; }; Student::Student(){} void Student::input() { for(int i =0; i<5; i++) { cin>>score[i]; } } int Student::calculateTotalScore() { int sum =0; for(int i =0; i<5; i++) { sum +=score[i]; } return sum; }

Load more conversations

Sort 335 Discussions, By:

Please Login in order to post a comment