Question

In: Mechanical Engineering

Write a MATLAB program to do the following: 1- Allows the user to enter unlimited number...

Write a MATLAB program to do the following:

1- Allows the user to enter unlimited number of data set.

2- Allows the user to exit the program at any time by entering zero.

3- Calculates and displays the following statistics for the entered data set:

a- Count of positive, negative, and total numbers.

b- Maximum and Minimum numbers.

c- Sum and Average of positive numbers.

d- Sum and Average of negative numbers.

e- Overall Sum and overall average of all numbers.

4- The output of each item should be displayed in two lines: One for the item title and the other for the results.

The output should be similar to the following:

Statistics of the data set:

---------------------------

Count of numbers: Positive = nn, Negative = nn, Total = nn

Maximum and Minimum numbers: Maximum number = n.nn, Minimum number = -n.nn

Solutions

Expert Solution

clear all;clc;

cnt_pos=0; %counting positive numbers
cnt_neg=0; %counting negative numbers
sum_pos=0; %summing positive numbers
sum_neg=0; %summing negative numbers
i=1;
num=input('Enter the number: ');
while(num~=0)
if num>0
cnt_pos=cnt_pos+1;
sum_pos=sum_pos+num;
else
cnt_neg=cnt_neg+1;
sum_neg=sum_neg+num;
end;
arr(i)=num;
i=i+1;
num=input('\nEnter the number: ');
end;
avg_pos=sum_pos/cnt_pos; %averaging positive numbers
avg_neg=sum_neg/cnt_neg; %averaging negative numbers
maximum=max(arr); %finding maximum of all numbers
minimum=min(arr); %finding minimum of all numbers
fprintf('Statistics of the data set:\n---------------------------\n');
fprintf('\nCount of numbers: Positive= %d, Negative= %d, Total= %d', cnt_pos,cnt_neg,length(arr));
fprintf('\nMaximum and Minimum Numbers: Maximum Number= %1.1f, Minimum Number= %1.1f',maximum,minimum);
fprintf('\nSum and average of positive numbers: Sum= %1.1f, Average= %1.1f',sum_pos,avg_pos);
fprintf('\nSum and average of negative numbers: Sum= %1.1f, Average= %1.1f \n',sum_neg,avg_neg);


Related Solutions

Write a program that runs on SPIM that allows the user to enter the number of...
Write a program that runs on SPIM that allows the user to enter the number of hours, minutes and seconds and then prints out the total time in seconds. Name the source code file “seconds.asm
Write a program that runs on SPIM that allows the user to enter the number of...
Write a program that runs on SPIM that allows the user to enter the number of hours, minutes and seconds and then prints out the total time in seconds. Name the source code file “seconds.asm Explain step by step
In Python, write a program that allows the user to enter a number between 1-5 and...
In Python, write a program that allows the user to enter a number between 1-5 and returns the vitamins benefits based on what the user entered. The program should: Continue to run until the user quits and Validate the user’s input (the only acceptable input is 0, 1, 2, 3, 4, or 5), If the user enters zero “0” the program should terminate You can use the following facts: 1- Vitamin A protects eyes from night blindness and age-related decline...
In Python, write a program that allows the user to enter a number between 1-5 and...
In Python, write a program that allows the user to enter a number between 1-5 and returns the vitamins benefits based on what the user entered. The program should: Continue to run until the user quits and Validate the user’s input (the only acceptable input is 0, 1, 2, 3, 4, or 5), If the user enters zero “0” the program should terminate You can use the following facts: 1- Vitamin A protects eyes from night blindness and age-related decline...
Program must be in C Write a program that allows the user to enter the last...
Program must be in C Write a program that allows the user to enter the last names of five candidates in a local election and the number of votes received by each candidate in two different arrays. The program should then output each candidate’s name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election. Example (Letters and numbers with underscore indicate an input):...
Write a program that allows the user to enter two integers and a character If the...
Write a program that allows the user to enter two integers and a character If the character is A, add the two integers If it is S, subtract the second integer from the first else multiply the integers Display the results of the arithmetic
Please write the code JAVA Write a program that allows the user to enter the last...
Please write the code JAVA Write a program that allows the user to enter the last names of five candidates in a local election and the number of votes received by each candidate. The program should then output each candidate’s name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election. A sample output is: Candidate      Votes Received                                % of Total Votes...
C++ Vector Write a program that allows the user to enter the last names of the...
C++ Vector Write a program that allows the user to enter the last names of the candidates in a local election and the votes received by each candidate. The program should then output each candidate's name, votes received by that candidate, and the percentage of the total votes received by the candidate. Assume a user enters a candidate's name more than once and assume that two or more candidates receive the same number of votes. Your program should output the...
Write a Python program that allows the user to enter the total rainfall for each of...
Write a Python program that allows the user to enter the total rainfall for each of 12 months into a LIST. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest rainfall amounts. Data: January 7.9 inches February 10.1 inches March 3.4 inches April 6.7 inches May 8.9 inches June 9.4 inches July 5.9 inches August 4.1 inches September 3.7 inches October 5.1 inches November 7.2...
Write the following program in Java. Ask the user to enter the number of rows and...
Write the following program in Java. Ask the user to enter the number of rows and columns for a 2-D array. Create the array and fill it with random integers using (int)(Math.random() * 20) (or whatever number you choose). Then, provide the user with several menu choices. 1. See the entire array. 2. See a specific row. 3. See a specific column. 4. See a specific value. 5. Calculate the average of each row. 6. Calculate the total of each...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT