.

Wednesday, December 11, 2019

Cis170 free essay sample

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 + \n); Console. WriteLine(Players 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 Players 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 lt; counter; i++) { Console. We will write a custom essay sample on Cis170 or any similar topic specifically for you Do Not WasteYour Time HIRE WRITER Only 13.90 / page WriteLine({0}\t\t{1}, playerName[i], playerScore[i]); } } static double CalculateAverageScore(ref int[] playerScore,int counter) { int total = 0, avg = 0; for (int i = 0; i lt; counter; ++i) { total += Convert. ToInt32(playerScore[i]); } if (playerScore. Length gt; 0) avg = total / counter; return avg; } static void DisplayBelowAverage(double avg, ref string[] playerName, ref int[] playerScore,int counter) { or (int i = 0; i lt; counter; i++) { if (playerScore[i] lt; avg) { Console. WriteLine({0}\t\t{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(); } } }

No comments:

Post a Comment