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

Q2: Create a text file containing the below mentioned Input Format. You have to

ID: 3712242 • Letter: Q

Question

Q2: Create a text file containing the below mentioned Input Format. You have to read the text file and store the content in the form of arrays. Given an array A of N integers, classify it as being Good Bad or Average. It is called Good, if it contains exactly X distinct integers, Bad if it contains less than X distinct integers and Average if it contains more than X distinct integers. Part b) Analysis your solution for part a of Q2, and Write the Worst Case Complexity in comments at the top of your.cpp file Submission instructions: Make sure that the main executable class is called 'main.cpp' spelt exactly as given here so the main function name must also be 'main'. (This is to enable automated testing Text File Input format: First line consists of a single integer T denoting the number of test cases. First line of each test case consists of two space separated integers denoting N and X. Second line of each test case consists of N space separated integers denoting the array elements. Output format: Print the required answer for each test case on a new line Constraints: 1T50 1 s X, N s 13000 1 A[i] 109 SAMPLE INPUT % SAMPLE OUTPUT Average Average Average Good 1425 4215 4 3 S 2 41 1 2 4 5

Explanation / Answer

/* The worst case complexity will be O(n^2) where n is the number of data in the array. As
we are comparing each element of the array with all the other elements of the array so the
total number of comparisons will be n^2.
*/

#include<iostream>
#include<fstream>

using namespace std;

int main(){

   int n,x,t,k;
   int data[1300];
   ifstream fin("input185.txt");
   if (!fin){
      cout << "Error opening file ";
      return 0;
   }
   fin >> t;
   if (t < 1 || t > 50){
      cout << "Invalid number of test cases ";
      return 0;
   }
   for (int i = 0; i<t; i++){
        fin >> n >> x;
        if ( n< 1 || x < 1 || n > 1300 || x > 1300){
           cout << "Invalid data ";
           continue;
        }
        int valid = 1;
        for (int j = 0; j<n; j++){
            fin >> data[j];
            if (data[j] < 1 || data[j] > 1000000){
               valid = 0;
               break;
            }
        }
        if (valid == 0)
           continue;
        int count = 0;
        for (int j = 0; j<n; j++){
            int count1 = 0;
            for (k = 0; k < n; k++){
                if (data[j] == data[k])
                   count1++;
            }
            if (count1 == 1)
               count++;
        }
        if (count == x)
           cout << "Good ";
        if (count < x)
           cout << "Bad ";
        if (count > x)
           cout << "Average ";

   }
}