C# SAMPLE CODE: For this task you are given a partially-complete program a progr
ID: 3712809 • Letter: C
Question
C#
SAMPLE CODE:
Explanation / Answer
Below is your program.
The bold part is what I changed
/* This program uses three parallel
* arrays to display the class name
* and how many places are left in that
* class.
*/
using System;
namespace ClassEnrolment {
class ClassEnrolment {
public static void Main() {
string[] className = new string[] { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" };
int[] currentEnrolment = new int[] { 25, 18, 32, 31, 28 };
int[] maximumEnrolment = new int[] { 29, 23, 32, 36, 31 };
Console.WriteLine("Number of places still available for each class. ");
// Write a "for" loop here, using the className.Length property.
// Do not change any of the existing lines of code.
// ...
// ...
// ...
for(int i=0;i<className.Length;i++)
{
int n=maximumEnrolment[i]-currentEnrolment[i];
if(n>0)
{
Console.WriteLine(className[i]+" has "+n+" places left");
}
}
for(int i=0;i<className.Length;i++)
{
int n=maximumEnrolment[i]-currentEnrolment[i];
if(n==0)
{
Console.WriteLine(className[i]+" is full");
}
}
ExitProgram();
}
public static void ExitProgram() {
Console.Write("Press enter to continue ...");
Console.ReadLine();
}
}
}
Output
UPDATED CODE
/* This program uses three parallel
* arrays to display the class name
* and how many places are left in that
* class.
*/
using System;
namespace ClassEnrolment {
class ClassEnrolment {
public static void Main() {
string[] className = new string[] { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" };
int[] currentEnrolment = new int[] { 25, 18, 32, 31, 28 };
int[] maximumEnrolment = new int[] { 29, 23, 32, 36, 31 };
Console.WriteLine("Number of places still available for each class. ");
// Write a "for" loop here, using the className.Length property.
// Do not change any of the existing lines of code.
// ...
// ...
// ...
for(int i=0;i<className.Length;i++)
{
int n=maximumEnrolment[i]-currentEnrolment[i];
if(n>0)
{
Console.WriteLine(className[i]+" has "+n+" places left");
} else if(n == 0) {
Console.WriteLine(className[i]+" is full");
}
}
ExitProgram();
}
public static void ExitProgram() {
Console.Write("Press enter to continue ...");
Console.ReadLine();
}
}
}
Output
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.