Question

In: Computer Science

A professor wants to do some research on students who use different kinds of computers. They...

A professor wants to do some research on students who use different kinds of computers. They are curious if there is any difference in average test scores between , for instance, Mac users and Windows users. Write a program to help with this, that behaves as follows.

  • The user repeatedly enters a computer type, picking Mac, Windows or Other by entering "m", "w", or "o", along with a test score from 0 to 100. The user enters "x" to indicate they are done inputting data.
  • The program will calculate the average test score for each computer type separately.
    • Note that this means you need 3 separate counters and 3 separate accumulators, one for each computer type. Each time a computer type and score is entered, you need to update the appropriate accumulator and counter. A switch would be very useful here!
  • When all input is complete, calculate and display the average test score for each computer type, with one decimal place.
  • If there are no students for a particular computer type, instead of outputting an average test score, only output "No Windows users", "No Mac users" or "No Other users".
  • Your program must work for upper or lowercase. In other words, all of these are valid inputs for computer type: "M", "m", "W", "w", "O", "o", "X", "x". This is easiest to do with a String variable and a switch statement with cases "stacked" on top of each other, or convert the string to upper or lower case before starting the switch.

Solutions

Expert Solution

Here is the code, I have tried to be as descriptive as possible :

#include <bits/stdc++.h>

using namespace std;

float sumW = 0, sumO = 0, sumM = 0;                // These values are the accumulators for each type of computer.
int countW = 0, countO = 0, countM = 0;         // These values the counters for each accumulator.

int main()
{
   while(1){                                                       // This will run until x or X is entered as an input.
       cout<<" Enter the type of computer or enter x/X to compute the scores : ";
       char choice;
       cin>>choice;
      
       int score;
       switch(choice)                                      // in each case we increment the values of the accumulator
       {                                                           // and the counter. except the x case in that , we print
           case 'm':                                          // the averages of the score or print no user if no entry of
           case 'M':                                          // that type is made.
               cout<<" Enter the score : ";
               cin>>score;
               sumM += score;
               countM++;
               break;
              
            case 'w':
            case 'W':
               cout<<" Enter the score : ";
               cin>>score;
               sumW += score;
               countW++;
               break;
              
           case 'o':
           case 'O':
               cout<<" Enter the score : ";
               cin>>score;
               sumO += score;
               countO++;
               break;
              
           case 'x':
           case 'X':
               if(sumM==0){
                   cout<<"No Mac Users.\n";
                   }
               else{
                   printf("The average test score for mac users is : %.1f\n", sumM/countM);
                   }
               if(sumW==0){
                   cout<<"No Windows Users.\n";
                   }
               else{
                   printf("The average test score for windows users is : %.1f\n", sumW/countW);
                   }
               if(sumO==0){
                   cout<<"No Other Users.\n";
                   }
               else{
                   printf("The average test score for other users is : %.1f\n", sumO/countO);
                   }
               exit(0);
               break;
           default:
           break;
       }
   }
    return 0;
}


Related Solutions

A political science professor is interested in comparing students who do and do not vote in...
A political science professor is interested in comparing students who do and do not vote in federal elections. She computes the mean grade point average for a random sample of 14 students who have voted in the last federal election to be 2.51 with a standard deviation of 0.44. She computes the mean grade point average for a random sample of 15 students who did not vote in the last election to be 2.98 with a standard deviation of 0.56....
Research Paradigms: Different kinds of research require different types of paradigms. Identify three types of research...
Research Paradigms: Different kinds of research require different types of paradigms. Identify three types of research and the appropriate paradigm for each.
A professor notices that more and more students are using their notebook computers in class, presumably...
A professor notices that more and more students are using their notebook computers in class, presumably to take notes. He wonders if this may actually improve academic success. To test this, the professor records the number of times each student uses his or her computer during a class for one semester and the final grade in the class (out of 100 points). If notebook computer use during class is related to improved academic success, then a positive correlation should be...
A college professor wants to select three students among twelve students to clean the room. The...
A college professor wants to select three students among twelve students to clean the room. The first student selected will clean the windows, the second student selected will do all the other work, while the third student selected will supervise all activities. In how many different ways can the professor select 3 students form this group.
New York wants to do a study to compare students at two different schools in the...
New York wants to do a study to compare students at two different schools in the city to see if student’s feelings about college are influenced by their tuition. The city takes a sample of 100 students from Barnard college whose tuition is 60 thousand dollars a year and 200 from Lehman College whose tuition is 15 thousand dollars a year. They ask each student the same question “Do you feel that your college is worth the tuition you pay...
New York wants to do a study to compare students at two different schools in the...
New York wants to do a study to compare students at two different schools in the city to see if student’s feelings about college are influenced by their tuition. The city takes a sample of 100 students from Barnard college whose tuition is 60 thousand dollars a year and 200 from Lehman College whose tuition is 15 thousand dollars a year. The ask each student the same question “Do you feel that your college is worth the tuition you pay...
A professor wants to determine if there is a difference between students' pre and post test...
A professor wants to determine if there is a difference between students' pre and post test after a semester of learning. 1. What could be the research question for this problem? 2. What could be the null hypothesis and alternative hypothesis for this problem? 3. Looking at the mean of both pro and post test, on the end-results below, does it REJECT or FAIL TO REJECT the null hypothesis and why? The results of the test showed this following: Paired...
A professor in a graduate course wants to form a team of three students to represent...
A professor in a graduate course wants to form a team of three students to represent the class at a national case competition? Of the 20 students in the class, 5 have undergraduate degrees in Economics, 9 in Engineering and 6 in business. If the team is formed at random, what is the probability that there will be at least two students with different undergraduate majors on the team?
a. How do experiments differ from other kinds of research designs? b. What are some examples...
a. How do experiments differ from other kinds of research designs? b. What are some examples of when other kinds of research designs would be used? c. What are the advantages and disadvantages of the kinds of research designs used in psychology?
Will students wait longer for the arrival of an instructor who is a full professor than...
Will students wait longer for the arrival of an instructor who is a full professor than for one who is a graduate student? This question was investigated by counting how many minutes undergraduate students waited in two small seminar classes, one taught by a full professor and one taught by a graduate student. The data (in minutes) are as follows: Graduate Student Instructor: 9, 11, 14, 14, 16, 19, 37 Full Professor: 13, 15, 15, 16, 18, 23, 28, 31,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT