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 C++ program that outputs to a file, final marks and average mark for a...
Write a C++ program that outputs to a file, final marks and average mark for a primary school class. Your program should also output to a second a file, the student names and their average mark in ascending order. This is an example of how your program in action could look like: Sample Input Please enter student name and student number Kgosi Kgosi 20150986 Please student marks for Setswana, Maths, Science, English, and Social Studies 80 70 80 65 100...
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
5. Write a CH program that takes the marks of a student as input and prints...
5. Write a CH program that takes the marks of a student as input and prints the grade on screen according to the following criteria: CRITERIA LESS THAN 60 GREATER THAN 60 BUT LESS THAN 65 GREATER THAN 65 BUT LESS THAN 70 GREATER THAN 70 BUT LESS THAN 75 GREATER THAN 75 BUT LESS THAN 80 GREATER THAN 80 BUT LESS THAN 85 GREATER THAN 85 BUT LESS THAN 90 GREATER THAN 90 GRADE F D D+ с C+...
Write a Java program that outputs the output below Student Name: Andrew Johnson Course: Biology 101...
Write a Java program that outputs the output below Student Name: Andrew Johnson Course: Biology 101 Quiz Average and percent weight (separated by a space): 87 15 Project Average and percent weight (separated by a space): 92 25 Exam Average and percent weight(separated by a space): 85 40 Final Exam and percent weight (separated by a space): 83 20 Final Grade in Biology 101 for Andrew Johnson is 86.7 The largest average was 92 The smallest average was 83 Thank...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT