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
Sort by
recency
|
409 Discussions
|
Please Login in order to post a comment
Hey everyone! This discussion about classes and objects in C++ is really interesting. I'm still learning this myself, can you tell me how to integrate classes and obejcts in my wordpress site ,so i can make it looks better with unique interface of drdrivingcars and vehicles looks.
class Student { private: int scores[5]; public: void input() { int i = 0; for(i=0;i<5;i++){ cin >> scores[i]; } } int calculateTotalScore() { int sum = 0; int i = 0; for(i=0;i<5;i++) { sum = sum + scores[i]; } return sum; }
};
include
using namespace std; class Student { public: int score[5]; void input(){ for (int i = 0; i < 5; i++) { cin>>score[i]; } } int total_number(){ int sum=0; for(int i=0;i<5;i++){ sum=sum+score[i]; } return sum; } }; int main(){ int n; cin>>n; Student *st = new Student [n]; for(int i=0;i
int kristen_score = st[0].total_number();
int count=0; for(int i=0;i
cout<
class Student{
};
Here's my question, why does looping with auto get random results? I used int scores[5] then in input and calculateTotalScore I used for (auto i: scores). I finally changed it to a for loop and it worked, but wasn't I technically doing the same thing??