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

SET OPERATION (2 Assignments) This assignment will have you working with Collect

ID: 3721893 • Letter: S

Question

  SET OPERATION (2 Assignments)

This assignment will have you working with Collections and reading in another text file. This time you will identify the people form the text file that fit in the following criteria: Those who took CS210, those who took CS211, those who took CS210 or CS211, those who took CS210 and CS211, those who took CS210 but not CS211, and finally those who took CS210 but not CS210. The text file consists of a list of students, theirs names, and the classes they took.

Part2: (GUI version)
You will also create a GUI version of the same program. In the GUI version will have a title, a drop box for the selection of the case (weather they are only in one class or the other, weather they took both), and a text area for they list results.

Read the text file and save student info into a data structure what you chosen.

---------------student.txt-----------

cs211 John
cs211 William
cs211 Susan
cs211 Jack
cs211 Jennifer
cs211 Sophia
cs211 Emma
cs211 Olivia
cs211 Eve
cs211 Tom
cs211 Lily
cs210 John
cs210 William
cs210 Susan
cs210 Jack
cs210 Jennifer
cs210 Sophia
cs210 Emma
cs210 Olivia
cs210 Isabella
cs210 Zoe

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

Output lists to screen.

those who took CS210

those who took CS211,

those who took CS210 or CS211,

those who took CS210 and CS211,

those who took CS210 but not CS211,

those who took CS210 but not CS210.

Explanation / Answer

Student .txt

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp
{
public partial class Form1 : Form
{
internal static readonly string[] separators = new[] { " " };
internal List<StudentsDto> studentList = null;
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
FileReadFromDrive();
}

internal void FileReadFromDrive()
{
using (StreamReader reader = File.OpenText(@"C:student.txt"))
{
string str = reader.ReadToEnd();
var result = str.Split(separators, StringSplitOptions.None);
if (result.Length >= 0)
{
studentList = new List<StudentsDto>();
foreach (var student in result)
{
var data = student.Split(' ');
studentList.Add(new StudentsDto() { Class = data[0], Name = data[1] });
}
}

var test = studentList;
}
}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
textBox1.Text = string.Empty;
IEnumerable<StudentsDto> findList = new List<StudentsDto>();
findList = null;
string criteria = comboBox1.SelectedItem.ToString();
var cs2011 = studentList.Where(x => x.Class == "CS211").ToList();
var cs2010 = studentList.Where(x => x.Class == "CS210").ToList();

switch (criteria)
{
case "CS210":
findList = studentList.Where(x=>x.Class == criteria).ToList();
break;
case "CS211":
findList = studentList.Where(x => x.Class == criteria).ToList();
break;
case "CS210 or CS211":
findList = studentList.Where(x => x.Class == "CS210" || x.Class == "CS211").ToList();
break;
case "CS210 and CS211":
findList = studentList.Where(x => x.Class == "CS210" && x.Class == "CS211").ToList();
break;
case "CS210 but not CS211":
var cs2010Names = cs2010.Select(x => x.Name).ToList();
findList = cs2011.Where(x => !cs2010Names.Contains(x.Name)).ToList();
break;
case "CS211 but not CS210":
var cs2011Names = cs2011.Select(x => x.Name).ToList();
findList = cs2010.Where(x => !cs2011Names.Contains(x.Name)).ToList();

break;
default:
return;
}

foreach (var student in findList)
{
textBox1.Text += student.Name + Environment.NewLine;
}
  
}
}
}