Question

In: Computer Science

Write a C++ program that outputs a histogram of student Marks for a Mid-term-1 Examination. The...

Write a C++ program that outputs a histogram of student Marks for a Mid-term-1 Examination. The program should input each student’s Marks as an integer and store the Marks in a dynamic array. Marks should be entered until the user enters -1 for marks. The program should then scan through the Dynamic array and compute the histogram. In computing the histogram, the minimum value of a marks is 0 but your program should determine the maximum value entered by the user. Then use a dynamic array to store and output the histogram. (20 points) For example, if the input is: 80 60 80 70 60 50 50 50 -1 Then the output should be: The frequency of 80's: 2 The frequency of 70's: 1 The frequency of 60's: 2 The frequency of 50's: 3

note: the arrays should be dynamic . furthermore the logic should not match other's logic, it should not be copy paste

Solutions

Expert Solution


#include <iostream>
#include <vector>
#include <bits/stdc++.h> 

using namespace std;

int main()
{
    ///Initilaze vector To get user input dynamically
    std::vector<int> myvector;
    
    //Getting User Inputs till user enters -1
    while (1) {
        int myint;
        std::cout << "Please enter some value (enter -1 to end):\n";
        std::cin >> myint;  
        if(myint == -1){
            break; 
        }
        myvector.push_back(myint);
    }
    
    //Getting the size of user Inputs
    int n = myvector.size();
    
    int i; 
  
    // Initialise a set 
    // to store the array values 
    set<int> s; 
  
    // Insert the array elements 
    // into the set 
    for (i = 0; i < n; i++) { 
  
        // insert into set 
        s.insert(myvector[i]); 
    } 
  
    set<int>::iterator it; 
  
    // Print the duplicates count 
    for (it = s.begin(); it != s.end(); ++it){ 
        int count = 0;
        for( i = 0; i < n;i++ ){
          if( myvector[i] == *it ){
            count++;  
          }  
        }
        cout << "The Frequency of " << *it <<"'s: " << count << "\n";
    }
    return 0;
}

Output:


Related Solutions

write a program on c++ that outputs a calendar for a given month in a given...
write a program on c++ that outputs a calendar for a given month in a given year, given the day of the week on which the 1st of the month was. The information in numeric format (months are: 1=Januay, 2=February 3=March, 4= April, 5= May, 6= June, 7= July... etc days are 1=Sunday, 2=Monday, 3= Tuesday, 4= Wednesday, 5= Thursday, 6= Friday and 7= Saturday ). The program output that month’s calendar, followed by a sentence indicating on which day...
USING C# 1. Write a program that takes outputs a string, an integer and a floating-point...
USING C# 1. Write a program that takes outputs a string, an integer and a floating-point number separated by commas. Sample output: Bob Marley, 20, 5.2 2. 2. Write a program that asks the user for a string of letters of any size (no spaces), and finally a special character (values 33 to 47 in the Ascii table, or ‘!’ to ‘/’). Generate a random number of any size, integer or floating point, and combine those three pieces of information...
C++ Write a program that takes a string and integer as input, and outputs a sentence...
C++ Write a program that takes a string and integer as input, and outputs a sentence using those items as below. The program repeats until the input string is "quit". If the input is: apples 5 shoes 2 quit 0 the output is: Eating 5 apples a day keeps your doctor away. Eating 2 shoes a day keeps your doctor away.
C++. Write a program that asks the user to enter a single word and outputs the...
C++. Write a program that asks the user to enter a single word and outputs the series of ICAO words that would be used to spell it out. The corresponding International Civil Aviation Organization alphabet or ICAO words are the words that pilots use when they need to spell something out over a noisy radio channel. See sample screen output for an example: Enter a word: program Phonetic version is: Papa Romeo Oscar Golf Romeo Alpha Mike The specific requirement...
Code in C Write a program whose inputs are three integers, and whose outputs are the...
Code in C Write a program whose inputs are three integers, and whose outputs are the largest of the three values and the smallest of the three values. Ex: If the input is: 7 15 3 the output is: largest: 15 smallest: 3 Your program must define and call the following two functions. The LargestNumber function should return the largest number of the three input values. The SmallestNumber function should return the smallest number of the three input values. int...
C++ Write a program that outputs an amortization schedule for a given loan. Must be written...
C++ Write a program that outputs an amortization schedule for a given loan. Must be written using user-defined functions must take at least 1 argument Output number of months, payment, interest to pay, principle to pay, and ending balance
Write a C program that calculates a student grade in the C Programming Class. Ask the...
Write a C program that calculates a student grade in the C Programming Class. Ask the user to enter the grades for each one of the assignments completed in class: Quiz #1 - 25 points Quiz #2 - 50 points Quiz #3 - 30 points Project #1 - 100 points Project #2 - 100 points Final Test - 100 points The total of the quizzes count for a 30% of the total grade, the total of the projects counts for...
Write a C program that outputs a formatted header line and creates 10 children processes each...
Write a C program that outputs a formatted header line and creates 10 children processes each of which displays a line of the output as shown below. Notice the values of Child no and x, they have to be the same as shown here while the processes PIDs values are based on the what your system assigns to these processes. Child    PID        PPID      X 0           13654    13653    5 1           13655    13653    10 2           13656    13653    15 3           13657    13653    20...
1. ​ a)​Write a Matlab program to define student grade program and student number with if-else...
1. ​ a)​Write a Matlab program to define student grade program and student number with if-else statement logic​​​​​​​​​ b)​Write a Matlab program for sensor selection of temperature, pressure, flow sensor with if-else statement logic​​​​​​​​​ ​ 2.​Assume there are four letters from an information source with probabilities as A1 0.5 A2 0.3 A3 0.1 A4 0.1 Generate the tag and find the corresponding gaps and binary values for each stage and the sequence of the symbols which are coded are a1a3a2a4a1.​​​...
C++ Task 1 Write a program that allocates an array large enough to hold 5 student...
C++ Task 1 Write a program that allocates an array large enough to hold 5 student test scores. Once all the scores are entered, the array should be passed to a function that sorts them in ascending order. Another function should be called that calculates the average score. The program should display the sorted list of scores and averages with appropriate headings. Input Validation: Do not accept negative numbers for test scores. Task 2 Modify the program so the lowest...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT