Help me please. I know nothing of coding, and I pay here for answers, and all I\
ID: 3671544 • Letter: H
Question
Help me please. I know nothing of coding, and I pay here for answers, and all I've been getting are copy paste answers. Please help. Thank you.....
I would like to know what you name the .txt files and where to save it, and what to put into them. This is a Windows Form application, so if you could please tell me your button names please.
Write an application that retrieves a student name and three scores per line from a text file. Process the values by calculating the average of the scores per student.Write the name and average to a different text file.Test your application with a minimum of eight records in the original file. Please help me out.. Thank you
Explanation / Answer
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace StudentAvg
{
public partial class StudentAvgs : Form
{
public StudentAvgs()
{
InitializeComponent();
}
private void buttonOpenStudentFile_Click(object sender, EventArgs e)
{
DialogResult r = openStudentFileDialog.ShowDialog();
if (r != DialogResult.OK) return;
textStudentFilename.Text = openStudentFileDialog.FileName;
if (!File.Exists(textStudentFilename.Text))
{
MessageBox.Show("Somehow you selected a file that doesn't exist.");
textStudentFilename.Text = "";
return;
}
}
private void StudentAvgs_Load(object sender, EventArgs e)
{
textStudentFilename.Text = "";
}
private void buttonSaveStudentFile_Click(object sender, EventArgs e)
{
if (textStudentFilename.Text == "")
{
MessageBox.Show("Must first select a valid Student file.");
return;
}
if (!File.Exists(textStudentFilename.Text))
{
MessageBox.Show(
"Student file was deleted or has gone missing since it was selected."
);
textStudentFilename.Text = "";
return;
}
DialogResult r = saveStudentFileDialog.ShowDialog();
if (r != DialogResult.OK) return;
if (File.Exists( saveStudentFileDialog.FileName ))
{
if (MessageBox.Show("Are you sure you want to replace that file?",
"File Already Exists", MessageBoxButtons.OKCancel) ==
DialogResult.Cancel)
return;
File.Delete( saveStudentFileDialog.FileName );
}
string[] lines = File.ReadAllLines( textStudentFilename.Text );
for (int i = 0; i < lines.Length; ++i )
{
string[] words = lines[i].Split(new char[] { ' ', ',', ' ' });
if (words.Length > 1)
{
double sum = 0.0;
for (int j = 1; j < words.Length; ++j)
sum += Convert.ToDouble(words[j]);
double avg = sum / (words.Length - 1);
lines[i] = words[0] + " " + Convert.ToString(avg);
}
}
File.WriteAllLines( saveStudentFileDialog.FileName, lines );
}
private void buttonQuit_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}
I have this code in java here i am providing you that code also
Please save your names and text in Scores.txt
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.