Question

In: Electrical Engineering

a) Write C code using if statements to display ‘Freshman, ‘Sophomore’, ‘Junior’ or ‘Senior’ based on...

a) Write C code using if statements to display ‘Freshman, ‘Sophomore’, ‘Junior’ or ‘Senior’ based on what value is in variable classification. Display ‘unknown ’ if classification does not contain ‘f’, ‘s’, ‘j’or ‘r’. Allow upper or lower case in variable color. In other words either ‘r’ or ‘R’ will display ‘Senior’.

b) Write C code to do the same thing as the previous problem, but use a switch statement.

Solutions

Expert Solution

Answer :- a) The C code has been written below using if statement-

#include<stdio.h>
int main()
{
char color, flag = 0;
printf("\n Enter a character ");
scanf("%c", &color);
if(color == 'f' || color == 'F'){
printf("\n Freshman \n");
flag = 1;
}

if(color == 's' || color == 'S'){
printf("\n Sophomore \n");
flag = 1;
}

if(color == 'j' || color == 'J'){
printf("\n Junior \n");
flag = 1;
}

if(color == 'r' || color == 'R'){
printf("\n Senior \n");
flag = 1;
}

if(flag == 0)
printf("\n Unlnown \n");

return 0;

}

Answer :- b) The C code using switch statement is written below-

//Answer :- a) The C code has been written below using if statement-

#include<stdio.h>
int main()
{
char color;
printf("\n Enter a character ");
scanf("%c", &color);
switch(color){
case 'F' :
case 'f' :{
printf("\n Freshman \n");
break;
}

case 'S' :
case 's' :{
printf("\n Sophomore \n");
break;
}

case 'J' :
case 'j' :{
printf("\n Junior \n");
break;
}

case 'R' :
case 'r' :{
printf("\n Senior \n");
break;
}

default:
printf("\n Unknown \n");

}
return 0;

}


Related Solutions

Considering a Character vector called statusDesc=c(“senior”,”sophomore”,”junior”,”freshman”). Write R code(s) to create a factor called statusFac that...
Considering a Character vector called statusDesc=c(“senior”,”sophomore”,”junior”,”freshman”). Write R code(s) to create a factor called statusFac that will take statusDesc as an argument and has four levels in the order of “freshman,” ”sophomore,” ”junior,” and “senior.” Use the following codes to generate 10 random numbers to represent 10 random ages. set.seed(1) ages=rnorm(10,24,24) Based on the variable ages, use cut() to create a factor called ageFac that has 4 levels “child”,”teen”,”adult”, and “senior”.   The corresponding age ranges are (3,13],(13,18],(18,60],and (60,120]. For example,...
12. Political Party Affiliation and Class level Freshman Sophomore Junior Senior Total Democrat 1 4 5...
12. Political Party Affiliation and Class level Freshman Sophomore Junior Senior Total Democrat 1 4 5 3 13 Republican 4 8 4 2 18 Green 1 3 3 2 9 Libertarian 1 1 2 1 5 Peace/Freedom 2 3 3 2 10 Total 6 15 12 7 55 Perform a hypothesis test to determine whether there is an association between class levels and political party affiliation.
A researcher is studying groups of freshman, sophomore, and junior students and finds a significant ANOVA...
A researcher is studying groups of freshman, sophomore, and junior students and finds a significant ANOVA with regards to the number of trips to the library each quarter. His data is summarized below. (Each group had 10 subjects; use α = .01) F= 4             S= 10                       J[s1]= 13                       MSerror (within) = 5 Assuming a significant F ratio (one way-between subjects ANOVA), do a Fisher’s Post-Hoc test with this information. Set α = .01.                                                                               a)  What is the critical value for the above test?                                (1 point)...
A university conducted a survey of 273 ​sophomore, junior, and senior undergraduate students regarding satisfaction with...
A university conducted a survey of 273 ​sophomore, junior, and senior undergraduate students regarding satisfaction with student government. Results of the survey are shown in the table by class rank. Sophomore Junior Senior Total Satisfied 45 65 63 173 Neutral 16 16 9 41 Not satisfied 17 15 27 59 Total 78 96 99 273 A survey participant is selected at random. What is the probability that he or she is a junior AND neutral ​? In other​ words, find​...
Satisified Freshmen Sophomore Junior Senior Yes 21 19 10 20 No 14 9 17 11 Directions:...
Satisified Freshmen Sophomore Junior Senior Yes 21 19 10 20 No 14 9 17 11 Directions: Use the crosstabe option in the Descriptives menu to answer the questions based on the following scenario. ( Be sure to select Chi-square from the sStatistics submenu and Observed, Expected, Row, and Column in the Cell submenu. Assume a level of significance of .05) The school district recently adopted the use of e-textbooks, and superintendent is interested in determining the level of satisfaction with...
Suppose you have four classifications: freshmen (f), sophomore (so), junior (j), and senior (se). You construct...
Suppose you have four classifications: freshmen (f), sophomore (so), junior (j), and senior (se). You construct a dummy variable, one for each classification that takes on the value of (1) should that classification be true for that observation and 0 otherwise. Further assume that you estimate the following model: E[GPA]= .5*ACT+1*So+-0.97*J+{c}*Se How much higher/lower is a Junior's GPA, after controlling for ACT, than for the omitted category?
Using c++, write a program that will display your name as a void function then will...
Using c++, write a program that will display your name as a void function then will perform the following by user-defined functions: a. to compute for the sum of two numbers (n1, n2) using function.
Write a verilog code for digital clock and display it’s seven segment using fpga?
Write a verilog code for digital clock and display it’s seven segment using fpga?
write the code of 4 digit 7-segment display using arduino uno in assembly language by using...
write the code of 4 digit 7-segment display using arduino uno in assembly language by using software AVR STUDIO 5.1?
Write a code using c# Maximum Sub Array.
Write a code using c# Maximum Sub Array.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT