Modify the Below server.cs and client.cs programs for C# , such that a client ca
ID: 3803331 • Letter: M
Question
Modify the Below server.cs and client.cs programs for C#, such that a client can enter a student ID like 'U101' and the server returns his/her major 'PHYSICS'. The client will automatically send the returned major back to the server in order to get the major's average GPA using the same XML file. Then, the client displays the major of the input student and the major's average GPA.
Client.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net.Sockets;
namespace ClientSocket
{
class Program
{
static void Main(string[] args)
{
TcpClient client = new TcpClient("127.0.0.1", 2055);
try
{
Stream s = client.GetStream();
StreamReader sr = new StreamReader(s);
StreamWriter sw = new StreamWriter(s);
sw.AutoFlush = true;
Console.WriteLine(sr.ReadLine());
while (true)
{
Console.Write("Enter a book title: ");
string title = Console.ReadLine();
sw.WriteLine(title);
if (title == "")
break;
Console.WriteLine(sr.ReadLine());
}
s.Close();
}
finally
{
client.Close();
}
}
}
}
Server.cs
/*
* C# program to accept a book title from clients and sends back
* its price using XML
*/
//SERVER SIDE PROGRAM
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Configuration;
namespace ServerSocket
{
class Program
{
static TcpListener listener;
const int LIMIT = 5;
public static void Query()
{
while (true)
{
Socket soc = listener.AcceptSocket();
Console.WriteLine("Connected: {0}", soc.RemoteEndPoint);
try
{
Stream s = new NetworkStream(soc);
StreamReader sr = new StreamReader(s);
StreamWriter sw = new StreamWriter(s);
sw.AutoFlush = true; // enable automatic flushing
sw.WriteLine("{0} books available", ConfigurationManager.AppSettings.Count);
while (true)
{
string bookTitle = sr.ReadLine();
if (bookTitle == "" || bookTitle == null)
break;
string price = ConfigurationManager.AppSettings[bookTitle];
if (price == null)
price = "Sorry, no such book!";
sw.WriteLine(price);
}
s.Close();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Console.WriteLine("Disconnected: {0}", soc.RemoteEndPoint);
soc.Close();
}
}
static void Main(string[] args)
{
IPAddress ipAd = IPAddress.Parse("127.0.0.1");
listener = new TcpListener(ipAd, 2055);
listener.Start();
Console.WriteLine("Server started, listening to port 2055");
for (int i = 0; i < LIMIT; i++)
{
Thread t = new Thread(new ThreadStart(Query));
t.Start();
Console.WriteLine("Server thread {0} started....", ++i);
}
}
}
}
Server_book.exe
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key = "Java 101" value="38.5"/>
<add key = "Cyber Security Handbook" value="72.99"/>
<add key = "Project Management" value="44.0"/>
<add key = "Advanced PHP" value="68.55"/>
<add key = "Beginning MySQL" value="29.25"/>
</appSettings>
</configuration>
Explanation / Answer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Gpa
{
class caluculator
{
public static int CSC103, BIO104, MAT107 = THREE;
static int IH101 = 2;
static int GSSC104 = 3;
public static int k, l, g, h, i, j;
static string studentName;
static float GPA;
static int registrationNo;
public static int csc, bio, mat, ich, gss;
public static void StudentName()
{
studentName = Console.ReadLine();
}
public static void RegistrationNo()
{
regNo = int.Parse(Console.ReadLine());
}
public static void ComputeGPA()
{
GPA =
Console.WriteLine("Thank You {0} For Using Our GPA Calculator. Hence, Your Overall GPA is: {1) ", studentName, GPA);
}
}
class CourseGrades:Program
{
public static void CSC101_Grade(int csc)
{
if (csc >= 80 && csc <= 100)
{
a = 3;
Console.WriteLine("Grade: A");
}
else if (csc <= 59 && csc >= 60)
{
b = 5;
Console.WriteLine("Grade: B");
}
else if (csc >= 60 && csc <=59)
{
c = 3;
Console.WriteLine("Grade: C");
}
else if (csc >=45 && csc <= 49)
{
d = 2;
Console.WriteLine("Grade: D");
}
else if (csc >=40 && csc <= 44)
{
e = 1;
Console.WriteLine("Grade: E");
}
else if (csc < 40 && csc >= 0)
{
f = 0;
Console.WriteLine("Grade: F");
}
else
{
Console.WriteLine("Please Enter Your Score");
}
}
public static void BIO101_Grade()
{
CSC101_Grade(bio);
}
public static void MAT101_Grade()
{
CSC101_Grade(mat);
}
public static void ICH101_Grade()
{
CSC101_Grade(ich);
}
public static void GSS101_Grade()
{
CSC101_Grade(gss);
}
static void Main(string[] args)
{
Console.WriteLine("Please Enter Your Name");
StudentName();
Console.WriteLine("Please Enter Your Reg No");
RegNo();
Console.WriteLine("Enter Your CSC 101 Score");
csc = int.Parse(Console.ReadLine());
CSC101_Grade(csc);
Console.WriteLine("Enter Your Mat 101 Score");
mat = int.Parse(Console.ReadLine());
MAT101_Grade();
Console.WriteLine("Enter Your Bio 101 Score");
bio = int.Parse(Console.ReadLine());
BIO101_Grade();
Console.WriteLine("Enter Your ICH 101 Score");
ich = int.Parse(Console.ReadLine());
ICH101_Grade();
Console.WriteLine("Enter Your GSS 101 Score");
gss = int.Parse(Console.ReadLine());
GSS101_Grade();
ComputeGPA();
Console.ReadKey();
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.