Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Modify the source code of the program so that is uses an array of Course objects

ID: 3594671 • Letter: M

Question

Modify the source code of the program so that is uses an array of Course objects instead of individual objects like
course1, course2, etc. The modified program should still output the same result.

CREATE AN ARRAY

The modified program output should look like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Course course1 = new Course("IT 145");
Course course2 = new Course("IT 200");
Course course3 = new Course("IT 201");
Course course4 = new Course("IT 270");
Course course5 = new Course("IT 315");
Course course6 = new Course("IT 328");
Course course7 = new Course("IT 330");
Console.WriteLine("Corrected Copy");
Console.WriteLine("List of courses:");
Console.WriteLine(course1.getName());
Console.WriteLine(course2.getName());
Console.WriteLine(course3.getName());
Console.WriteLine(course4.getName());
Console.WriteLine(course5.getName());
Console.WriteLine(course6.getName());
Console.WriteLine(course7.getName());
}
}
class Course
{
private string name = "";
public Course(string name)
{
this.name = name;
}
public string getName()
{
return name;
}
}
}

List ofcourses: IT 145 200 IT 201 IT 270 IT 315 IT 328 IT 330 Press any key to continue . . . IT

Explanation / Answer

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Course[] courses = new Course[7];
courses[0] = new Course("IT 145");
courses[1] = new Course("IT 200");
courses[2] = new Course("IT 201");
courses[3] = new Course("IT 270");
courses[4] = new Course("IT 315");
courses[5] = new Course("IT 328");
courses[6] = new Course("IT 330");
Console.WriteLine("Corrected Copy");
Console.WriteLine("List of courses:");
for(int i=0;i<courses.Length;i++) {
Console.WriteLine(courses[i].getName());
}

}
}
class Course
{
private string name = "";
public Course(string name)
{
this.name = name;
}
public string getName()
{
return name;
}
}
}

Output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote