Write a program using one-dimensional array that searches a number if it is found on the list of the given 5 input numbers and locate its exact location in the list.
Sample input/output dialogue:
Enter a list of numbers: 5 4 8 2 6
Enter a number to be searched: 2 2 found in location 4
Write a program using one-dimensional array that searches a number if it is found on the list of the given 5 input numbers and locate its exact location in the list.
Sample input/output dialogue:
Enter a list of numbers: 5 4 8 2 6
Enter a number to be searched: 2 2 found in location 4
Write a program using one-dimensional array that searches a number if it is found on the list of the given 5 input numbers and locate its exact location in the list.
Sample input/output dialogue:
Enter a list of numbers: 5 4 8 2 6
Enter a number to be searched: 2 2 found in location 4
Write a program using one-dimensional array that searches a number if it is found on the list of the given 5 input numbers and locate its exact location in the list.
Sample input/output dialogue:
Enter a list of numbers: 5 4 8 2 6
Enter a number to be searched: 2 2 found in location 4
Write a program using two-dimensional arrays that computes the sum of data in rows and sum of data in columns of the 3x3 (three by three) array variable n[3[3].
Sample input/output dialogue:
5 9 8 = 22
3 8 2 = 13
4 3 9 = 16
---------------
12 20 19
Question 4
A) Write a shell script that does the following
Allows the user to enter seven urls into a text file.
Check to see the status of the links as in whether they are working or not Write the name of the url and it’s status into another file.
Append to the file how many urls are working and how many are broken.
B) With a working example show how IO Redirection works in shell scripting.
C) With examples show how each of these external commands work Awk
Sed Grep
D) Why would this process give an error
1) first create the file
touch my_example.sh
2) open it in an editor
gedit my_example.sh
3) write some code
#!/bin/sh
echo “Shell scripting is fun.” 4) run the file ./my_example.sh
Question 3
Write a shell script that allows a user to write a nursery rhyme directly from the CLI and have the rhyme stored in a text file.
Your script should then replace all vowels in the rhyme with the letter “t”
Your script should also count the number of lines in the rhyme
Your script should make a copy of the text file and append all the characters of the first file into the second file into it.
Then delete all the contents of the first file.
B) Give four working examples of how to use grep in shell scripting,
C) list all hidden files in the present working directory showing all hidden files and in the long format
D) Explain the difference between ls -l > mylisting.txt and ls -l >> mylisting.txt [4 marks]
Question 2
A) The AIT canteen wants you to write a script for them which would do the following
I) receive records from the user and keep these records into a file, the records must include
ID
Name of meal
Price of meal
Quantity bought today
Sales made for the day
Today the sales person wants to make seven entries into the file via the command line interface.
Your script should be able to find to present the sales person with the ability to
Search for a particular meal by ID
Search for a particular meal by name
find out how much money has been made from the sales of a particular
meal
list all records
list all meals and their prices
list a particular meal and its price
B) With a shell script explain how to use case
C) With code explain how the following work
if statements
if else statements
if elif else fi statements
D) Explain the difference between= grep -i "some string" some file and grep -iw "some string" some file
Question 1
A) Write a game entirely in shell script which generates an unknown number and prompts the player to enter a number. Your game should receive the number and compare it to the generated number, let your game tell the player whether the number entered is higher than or lower than the hidden number until the player is able guess the number or quit the game, upon guessing the right number the game should congratulate the player for winning and tell the player how many attempts were made before guessing the right number.
B) Write a shell script that uses a function to count the number of files in the present working directory and output their number to the screen.
C)Explain with examples how to make variables available to child processes/shells
D) Many beginners are confused about the difference between the working of touch and of cat, could you please make the difference clear with an example
Write a class C2 that inherits all the functionality of A2 and B2,
// with the same stipulation that it should take f() from A2 and g() from B2.