In: Computer Science
1.Write a loop to print a list of numbers starting at 64 and ending at 339. Justify your syntax.
2. Write a switch statement that uses the colour of a swab sample of COVID testing vehicle to send a message to a local doctor. Use the messages given for each colour in the table below. Justify your answer.
Colour Message
Blue “No virus”
Yellow “Needs to be under observation”
Red “Needs to be admitted in COVID ward” 3.
Note: In the question, it not specified the language like c, c++ or java, etc so I write the c++ syntax
Write a loop to print a list of numbers starting at 64 and ending at 339. Justify your syntax.
for (int i = 64 ; i<= 339 ; i++) // Here is for loop which starts from 64
// and runs upto 339
{
cout<<i<<endl; // output statement to print the value of i
}
2. Write a switch statement that uses the colour of a swab sample of COVID testing vehicle to send a message to a local doctor. Use the messages given for each colour in the table below. Justify your answer.
Colour Message
switch(colour) // Here we make the switch statement and take color as an argument for matching case
{
case Blue: // if colour is blue the case blue will be executed
cout<<"No virus"<<endl; // Here is output statement to print result of colour
break; // Here is break statement to break the switch case after find the match
case Yellow: // if colour is Yellow the case blue will be executed
cout<<"Needs to be under observation"<<endl; // Here is output statement to print result of colour
break; // Here is break statement to break the switch case after find the match
case Red: // if colour is red the case blue will be executed
cout<<"Need to be admitted in COVID ward"<<endl; // Here is output statement to print result of colour
break; // Here is break statement to break the switch case after find the match
default: // Here is the default case for wrong input other than the desired input
break; // Here is break statement which break the further operation
// and get you out out of the switch statement
}
Note: Justification of each line of syntax wrote in front of that line after the double forward slash
Make sure to hit the like button if you find thid helpful for you THANK YOU AND HAPPY LEARNING!