1e. Write a script which receives a list of parameters. If no parameters are rec
ID: 3591358 • Letter: 1
Question
1e. Write a script which receives a list of parameters. If no parameters are received, output an error message. Otherwise, iterate through the list and, using a case statement, test each item in the list to see if it starts with a capital letter, lower case letter, digit or other. Count each type and output at the end the total for each category (capital, lower case, digit, other).
1f. Write a script to input a list of positive numbers from the user using a while loop (exit the loop upon a negative number), storing each input as an array element. Using a for loop, iterate through the list and compute the sum, average, maximum and minimum elements in the array. Output these results.
1g. Write a script to determine if a parameter supplied to the script is a palindrome or not. A palindrome is a string that reads the same forward and backward. To accomplish this, you will need to loop from 0 to the halfway point in the string and compare the character at location i to the character at location length – i – 1 where length is the length of the string. If, after passing halfway through, the two compared characters match in each iteration, then output the parameter and that it is a palindrome, else output the parameter and that it is not a palindrome.
1h. Create a script containing a function of the code defined in #17 and code after the function that defines an array of several strings, some of which are palindromes and some of which are not and then code to iterate through the array, calling the palindrome function passing each array element as a parameter.
1i. Examine the file /etc/rc.d/init.d/atd. This is a script that allows the system administrator to control the atd service, starting it, stopping it, etc. This script file consists primarily of a series of functions and a case statement. The idea is that someone calls this program using ./atd command where command is then compared in the case statement which then calls upon one of the functions, or if the command is not legal, it outputs a usage statement. In a similar way, write a script that has a case statement to see if the user has passed the script one of these commands: hello or start, goodbye or stop or quit, help. If hello or start, then call a function which outputs a personalized greeting to the user using the value in the variable $USER and the date. If goodbye/stop/quit, output a goodbye message. If help, output a message that provides a brief explanation on how to use Linux (e.g., Consult man pages, read the textbook, etc). If there is no command or the command is any other word, output a usage statement.
Explanation / Answer
Answering this in C# language :
1 e)
using System;
class Program
{
static void Main()
{
List<string> list1 = new List<string>(){"Alex","fox","1234","@A12a3"}; --Declaring the list : Note put the whole code in Try block and write the error message in catch block.
Public int func(List<string> list1) --defining the function
{ char grade;
int C1=0; int C2=0; int C3=0; int C4=0;
foreach (var i in list1)
{
if(char.isUpper(i[0]))
{ grade = 'A';}
else if(char.isLower(i[0])
{ grade = 'B';}
else if (Regex.IsMatch(i, @"^d+"))
{ grade = 'C';}
else{grade = 'D';}
switch (grade)
{
case 'A':
C1++;
break;
case 'B':
C2++;
break;
case 'C':
C3++;
break;
case 'D':
C4++;
break;
default:
Console.WriteLine("Invalid grade");
break;
}
}
Console.WriteLine("Upper"+ C1+" Lower"+C2+" Number"+C3+" Other"+C4);
return 0;
}
func(list1); -- calling the function
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.