NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace SarreScoresFull
{
public class Marks
{
// constant for the correct password
const string CorrectPassword = "OpenSimSim";

// array of student names
private string[] studentNames = new string[]{
"Dave", "George", "Alex", "Danny", "Ian", "Hannan", "Muna"
};

// 2D array of marks(item : class test, conical basket, destructive testing, overall mark)
// The default values of numeric array elements are set to zero
private double[,] studentMarks = new double[7, 4];

// the count of failed login
private static int loginFailCount = 0;

public enum LoginStatus
{
LoginSuccess,
LoginFail,
LoginFailForever
}

public enum SaveStatus
{
Success,
BadUserName,
BadClassTest,
BadConicalBasket,
BadDestructiveTesting
}

public Marks()
{

}

/// <summary>
/// Validate the password
/// </summary>
/// <param name="loginPassword"></param>
/// <returns></returns>
public LoginStatus validateLogin(string loginPassword)
{
bool isCorrectPassword = (loginPassword == CorrectPassword);

if (!isCorrectPassword)
{
loginFailCount++;
if (loginFailCount >= 3)
return LoginStatus.LoginFailForever;
else
return LoginStatus.LoginFail;
}

return LoginStatus.LoginSuccess;
}


public SaveStatus storeMarkEntry(string studentName, string classTestText, string conicalBasketText, string destructiveTestingText)
{
double classTest;
double conicalBasket;
double destructiveTesting;

// validate and convert strings into double
if (!studentNames.Contains(studentName))
return SaveStatus.BadUserName;

classTest = _convertToStudentMark(classTestText);
if (classTest < 0)
return SaveStatus.BadClassTest;

conicalBasket = _convertToStudentMark(conicalBasketText);
if (conicalBasket < 0)
return SaveStatus.BadConicalBasket;

destructiveTesting = _convertToStudentMark(destructiveTestingText);
if (destructiveTesting < 0)
return SaveStatus.BadDestructiveTesting;

// store the mark entry
_storeMarkEntry(studentName, classTest, conicalBasket, destructiveTesting);

return SaveStatus.Success;
}

/// <summary>
/// Convert the text to the student mark with validation.
/// </summary>
/// <param name="studentMarkText"></param>
/// <returns>
/// the mark in range of 0 ~ 100. -1 when invalid.
/// </returns>
private double _convertToStudentMark(string studentMarkText)
{
double mark;
try
{
mark = Convert.ToDouble(studentMarkText);
}
catch (Exception)
{
// return invalid value
return -1;
}

// check whether mark is in the range 0 ~ 100
if (mark < 0 || mark > 100)
{
mark = -1;
}

return mark;
}

/// <summary>
/// Store the marks according to the student name.
/// </summary>
/// <param name="studentName"></param>
/// <param name="classTest"></param>
/// <param name="conicalBasket"></param>
/// <param name="destructiveTesting"></param>
/// <returns></returns>
private void _storeMarkEntry(string studentName, double classTest, double conicalBasket, double destructiveTesting)
{
int index;

// find the index of given student name
index = Array.IndexOf(studentNames, studentName);

// store the marks
studentMarks[index, 0] = classTest;
studentMarks[index, 1] = conicalBasket;
studentMarks[index, 2] = destructiveTesting;

// calculate the overal mark
studentMarks[index, 3] = classTest * 0.40 + conicalBasket * 0.40 + destructiveTesting * 0.20;
}

/// <summary>
/// Give the string of all marks ordered by student name
/// </summary>
/// <returns></returns>
public string getMarksOrderedbyName()
{
_sortMarksByName();

return _getAllMarksString();
}

/// <summary>
/// Give the string of all marks ordered by score
/// </summary>
/// <returns></returns>
public string getMarksOrderedbyScore()
{
_sortMarksByScore();

return _getAllMarksString();
}

private void _sortMarksByName()
{
string tempString = "";
double tempValue = 0;

for (int i = 0; i < studentNames.Length; i++)
{
for (int j = i + 1; j < studentNames.Length; j++)
{
if (studentNames[i].CompareTo(studentNames[j]) > 0)
{
// swap the student names
tempString = studentNames[i];
studentNames[i] = studentNames[j];
studentNames[j] = tempString;

// swap the student marks
for (int k = 0; k < 4; k++)
{
tempValue = studentMarks[i, k];
studentMarks[i, k] = studentMarks[j, k];
studentMarks[j, k] = tempValue;
}
}
}
}
}

/// <summary>
/// Sort the mark entries according to the student score
/// </summary>
private void _sortMarksByScore()
{
string tempString = "";
double tempValue = 0;

for (int i = 0; i < studentNames.Length; i++)
{
for (int j = i + 1; j < studentNames.Length; j++)
{
if (studentMarks[i, 3] < studentMarks[j, 3])
{
// swap the student names
tempString = studentNames[i];
studentNames[i] = studentNames[j];
studentNames[j] = tempString;

// swap the student marks
for (int k = 0; k < 4; k++)
{
tempValue = studentMarks[i, k];
studentMarks[i, k] = studentMarks[j, k];
studentMarks[j, k] = tempValue;
}
}
}
}
}

private string _getAllMarksString()
{
var sb = new StringBuilder();
string formatString = "{0,-8} {1,-8} {2,-8} {3,-15} {4,-12:0}rn";
sb.AppendFormat(formatString, "Name", "Test", "Basket", "Destructive", "Final Grade");

// prepare the output string
for (int i = 0; i < studentNames.Length; i++)
{
sb.AppendFormat(formatString,
studentNames[i],
studentMarks[i, 0],
studentMarks[i, 1],
studentMarks[i, 2],
studentMarks[i, 3]);
}

return sb.ToString();
}
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.