تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
حل برنامج بلغة c++
#1
السلام عليكم

لو سمحتوا ممكن حد يحل لي هذا البرنامج ب C++

Write a program to compute and print a distribution of input grades by using an array of counters .The input is a sequence of grades ,terminated by a negative number ,which raises a Constraints _Error exception the grades are natural type (non-negative integers).
There are 10 categories of grades (0-9,10 -19,….,90 -100). The grades themselves are used to compute indexes into an array of counters , one for each grade category. Invalid input grades are detected by trapping indexing errors in the counter array .A grade of 100 is special in the computation of the grade distribution because the categories all have 10 possible grade values ,except the highest ,which has 11(90,91,…..,100). (The fact that there are more possible A grade than Bs or Cs is conclusive evidence of the generosity of teachers ). The grade of 100 are also handled in the same exception handler that is used for invalid input data.

شاكرين لكم حسن تعاونكم
الرد }}}
تم الشكر بواسطة:
#2
كود :
#include <iostream>
#include <vector>

void computeGradeDistribution() {
   std::vector<int> gradeCounts(11, 0); // Initialize an array of counters for grade categories

   while (true) {
       int grade;
       std::cout << "Enter a grade (-1 to quit): ";
       std::cin >> grade;

       if (grade == -1) {
           break;
       }

       if (grade < 0 || grade > 100) {
           std::cout << "Invalid grade" << std::endl;
           continue;
       }

       // Increment the counter for the corresponding grade category
       int category = grade / 10;
       gradeCounts[category]++;
   }

   std::cout << "Grade Distribution:" << std::endl;

   for (int i = 0; i < gradeCounts.size(); i++) {
       if (i == 10) {
           std::cout << "100: " << gradeCounts[i] << std::endl;
       } else {
           int lowerBound = i * 10;
           int upperBound = (i * 10) + 9;
           std::cout << lowerBound << "-" << upperBound << ": " << gradeCounts[i] << std::endl;
       }
   }
}

int main() {
   computeGradeDistribution();
   return 0;
}
الرد }}}
تم الشكر بواسطة:



التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم