Sunday, September 15, 2019
Cis170 Essay
using System. Collections. Generic; using System. Linq; using System. Text; namespace Lab5A { class Program { static void Main(string[] args) { string[] playerName = new string[100]; int[] playerScore = new int[100]; int c = 0; c=InputData(ref playerName, ref playerScore); double avg= CalculateAverageScore(ref playerScore,c); Console. WriteLine(ââ¬Å"Name Scoreâ⬠); DisplayPlayerData(ref playerName, ref playerScore, c); Console. WriteLine(); Console. WriteLine(ââ¬Å"Average Score: â⬠+ avg + â⬠ââ¬Å"); Console. WriteLine(ââ¬Å"Playerââ¬â¢s Who Scored Below Averageâ⬠); Console. WriteLine(ââ¬Å"Name Scoreâ⬠); DisplayBelowAverage(avg, ref playerName, ref playerScore,c); } static int InputData(ref string[] player, ref int[] score) { int addName = 0,counter=0; do { Console. Write(ââ¬Å"Enter Playerââ¬â¢s Name (Q to quit): ââ¬Å"); player[counter] = Console. ReadLine(); if (player[counter] == ââ¬Å"qâ⬠|| player[counter] == ââ¬Å"Qâ⬠) { addName = 1; } else { Console. Write(ââ¬Å"Enter score for {0}: ââ¬Å", player[counter]); score[counter] = Convert. ToInt32(Console. ReadLine()); counter++; } } while (addName ! = 1); eturn counter; } static void DisplayPlayerData(ref string[] playerName, ref int[] playerScore,int counter) { for (int i = 0; i < counter; i++) { Console. WriteLine(ââ¬Å"{0} {1}â⬠, playerName[i], playerScore[i]); } } static double CalculateAverageScore(ref int[] playerScore,int counter) { int total = 0, avg = 0; for (int i = 0; i < counter; ++i) { total += Convert. ToInt32(playerScore[i]); } if (playerScore. Len gth > 0) avg = total / counter; return avg; } static void DisplayBelowAverage(double avg, ref string[] playerName, ref int[] playerScore,int counter) { or (int i = 0; i < counter; i++) { if (playerScore[i] < avg) { Console. WriteLine(ââ¬Å"{0} {1}â⬠, playerName[i], playerScore[i]); } } Console. ReadLine(); } } } Part B: using System; using System. Collections. Generic; using System. Linq; using System. Text; using System. Collections; namespace Week_5_iLab_Part_B { class Program { static void Main(string[] args) { string response = ââ¬Å"yâ⬠; ArrayList LastNameAL = new ArrayList(); //Console. Write(ââ¬Å"Enter a last name: ââ¬Å"); //LastNameAL. Add(Console. ReadLine()); //Console. Write(ââ¬Å"Keep Going? (Y/N) ââ¬Å"); //response = Console. ReadLine(); while (response == ââ¬Å"yâ⬠) { Console. Write(ââ¬Å"Enter a last name: ââ¬Å"); LastNameAL. Add(Console. ReadLine()); Console. Write(ââ¬Å"Keep Going? (y/n) ââ¬Å"); response = Console. ReadLine(); } Console. WriteLine(LastNameAL. Count + â⬠last names entered. ââ¬Å"); Console. WriteLine(ââ¬Å"Last names in ascending order. ââ¬Å"); LastNameAL. Sort(); foreach (string s in LastNameAL) { Console. WriteLine(s); } Console. WriteLine(ââ¬Å"Last names in descending order. ââ¬Å"); LastNameAL. Reverse(); foreach (string s in LastNameAL) { Console. WriteLine(s); } Console. ReadLine(); } } }
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.