Create array of structure to store the details of voter. Create a menu for data creation, display, and check the availability of data and eligibility to vote. Also check if he is eligible to vote.
Write a function to add two 1D array elements. Use call by reference and return the sum array elements to the main function to printWrite a function to add two 1D array elements. Use call by reference and return the sum array elements to the main function to print
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.
[10 marks]
B) With a working example show how IO Redirection works in shell scripting.
[7marks]
C) With examples show how each of these external commands work
Awk
Sed
Grep
[4 marks]
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.
[9 marks]
4
B) Give four working examples of how to use grep in shell scripting,
[6 marks]
C) list all hidden files in the present working directory showing all hidden files and in the long format
[6 marks]
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
3
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
[10marks]
B) With a shell script explain how to use case
[9marks]
C) With code explain how the following work
if statements
if else statements
if elif else fi statements
[4 marks]
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.
[10 marks]
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.
[10marks]
C)Explain with examples how to make variables available to child processes/shells
Mr. Seth is a Goldsmith. He wants to know the amount of money earned from the sale. On a Normal day. i.c.. Weekday there is a sale of Rs. 10000/- which is fixed. On a weekend, there is an additional sale of Rs. 5000/-, and on a festival day (be it either week day or week
end), there is an additional sale of Rs. 20000/-.
Following are requirements to solve the problem
a. The type of day i.e., weekend or festival day has to be captured. b. Check for the type of day and compute the total amount of sale
c. Display the amount of sale in Rupees.
Create array of structure to store the details of voter. Create a menu for data creation, display, and check the availability of data and eligibility to vote. Also check if he is eligible to vote.
Write a function to add 2D array using pointer. Return the array using pointer. (call by value)
Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.
Ex 1:
Input: num = [1,3,5,6], target = 5
Out: 2
Ex 2:
Input: num = [1,3,5,6], target = 2
Out: 1
Ex 3:
Input: num = [1,3,5,6], target = 7
Out: 4
Ex 4:
Input: num = [1,3,5,6], target = 0
Out: 0
Ex 5:
Input: num = [1], target = 0
Out: 0
please follow the below program finish it in C language.
#include <stdio.h>
#include <stdlib.h>
int nums[1024];
int main(){
FILE *fp;
fp=fopen("binarysearch.txt","r");
if(fp==NULL){
printf("The input file does not exist.\n");
exit(-1);
}
int target,size = 0,i;
fscanf(fp, "%d", &target);
while (!feof(fp)){
fscanf(fp, "%d", &(nums[size]));
size ++;
}