0

Is it possible to put these two functions to some classes?

#include <iostream> #include <string> using namespace std; //Functions that assigns values to array "points" from user's input void ReadPoints(int points[5]) { for (int i = 0; i < 5; i++) { cin >> points[i]; } } //Function that converts points to different grades void PointsToGrade(char grade[], int points[]) { const char *dataGrades[] = {"A","B","C","D","E", "F"}; for (int i = 0; i < 5; i++) { if (points[i] > 90) { grade[i] = *dataGrades[0]; } else if (points[i] > 70 && points[i] < 90) { grade[i] = *dataGrades[1]; } else if (points[i] > 50 && points[i] < 70) { grade[i] = *dataGrades[2]; } else if (points[i] > 30 && points[i] < 50) { grade[i] = *dataGrades[3]; } else if (points[i] > 10 && points[i] < 30) { grade[i] = *dataGrades[4]; } else { grade[i] = *dataGrades[5]; } } } int main() { //Creating an array wich is gonna be filled by user's input int points[5]; //Calling the function ReadPoint there is sended array "points" as an argument and dispaying the values of array "points" filled by user ReadPoints(points); int i; for (i = 0; i < 5; i++) { cout << points[i] << "\t\t"; } // Creating an array "grade" wich will be filled by grades char grade[5]; PointsToGrade(grade, points); for (i = 0; i < 5; i++) { cout << grade[i] << "\t\t"; } cout << endl; system("pause"); return 0; }

3rd May 2021, 1:39 AM
Pozik
Pozik - avatar
4 Answers
0
Yes, but why?
3rd May 2021, 2:04 AM
äœ çŸ„é“èŠć‰‡ïŒŒæˆ‘äčŸæ˜Ż
äœ çŸ„é“èŠć‰‡ïŒŒæˆ‘äčŸæ˜Ż - avatar
0
Learn and know how to use classes. I tried and gott many mistakes so
3rd May 2021, 3:11 AM
Pozik
Pozik - avatar
0
An important thing to learn while learning about classes is where to use them. Your code does not need classes. If you need practise in OOP, I suggest you search the web for exercises.
3rd May 2021, 3:30 AM
XXX
XXX - avatar
0
If u guys gonna show me how to it here I may have better understanding
3rd May 2021, 1:19 PM
Pozik
Pozik - avatar