0% found this document useful (0 votes)
95 views

CS411 Assignment No 1

This document provides instructions for a programming assignment to update student data stored in an XML file. It includes code to load student data from an XML file, display the existing details, prompt the user to select a student to edit, find and update the selected student's data, and save the updated XML file. The programming language used is C# and the task involves reading and writing XML files to manage student records in a database.

Uploaded by

Hira Jamil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
95 views

CS411 Assignment No 1

This document provides instructions for a programming assignment to update student data stored in an XML file. It includes code to load student data from an XML file, display the existing details, prompt the user to select a student to edit, find and update the selected student's data, and save the updated XML file. The programming language used is C# and the task involves reading and writing XML files to manage student records in a database.

Uploaded by

Hira Jamil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Visual Programming (CS411)

Assignment#01
Bc190402697
Total marks = 20

Deadline Date = 15-11-2023

Solution:
using System;
using System.Xml.Linq;
class StudentDataUpdater
{
static void Main(string[] args)
{
// Read student data from XML file
XDocument doc = XDocument.Load("studentData.xml");
XElement students = doc.Element("students");
// Display all student details
Console.WriteLine("Existing Student Details:");
foreach (XElement student in students.Elements("student"))
{
int studentId = Convert.ToInt32(student.Element("id").Value);
string name = student.Element("name").Value;
string vuId = student.Element("vuId").Value;
double cgpa = Convert.ToDouble(student.Element("cgpa").Value);
Console.WriteLine("Student ID: {0}, Name: {1}, VU ID: {2}, CGPA: {3}", studentId,
name, vuId, cgpa);
}
// Prompt user to enter student number for editing
Console.WriteLine("\nEnter the student number you want to edit: ");
int studentNumber = Convert.ToInt32(Console.ReadLine());
// Find the student element with the specified student number
XElement studentToEdit = students.Elements("student").Where(s =>
Convert.ToInt32(s.Element("id").Value) == studentNumber).FirstOrDefault();
if (studentToEdit != null)
{
// Update student details
Console.WriteLine("\nEnter the updated details for student ID {0}:", studentNumber);
Console.WriteLine("Enter updated name: ");
string updatedName = Console.ReadLine();
Console.WriteLine("Enter updated VU ID: ");
string updatedVuId = Console.ReadLine();
Console.WriteLine("Enter updated CGPA: ");
double updatedCgpa = Convert.ToDouble(Console.ReadLine());
// Update student element with new values
studentToEdit.Element("Anas yasir").Value = updatedName;
studentToEdit.Element("BC190402697").Value = updatedVuId;
studentToEdit.Element("2.64").Value = updatedCgpa.ToString();
// Save the updated student data to the XML file
doc.Save("studentData.xml");
Console.WriteLine("\nStudent details updated successfully!");
}
else
{
Console.WriteLine("Student with the specified student number not found.");
}

You might also like