First watch the following short video and do the following:https://www.youtube.com/watch?v=mD0Nnem00l8&t=1s
1. Run the shell program, the following command-line arguments: “./shell /bin/cat shell.h”
2. Take a snapshot of the output and upload it on Canvas. Explain the output considering
the fact that “cat” program concatenate files to the standard output stream.
—————————————————————————————————————————————–3. First, predict the output of the following C program. Then, replace both of the goto statements
with other valid C statements. (Note: goto statement is similar to an unconditional jump in
assembly programming; i.e. the next statement executed after a goto LABEL statement is the
statement that has been labeled by LABEL.)
#include
void main(void){
int sum = 0, i = 0;
for(; i < 100;i++)
if(i % 10 == 5)
goto PRINT;
else
ADD: sum += i;
PRINT: printf("i = %d\n", i);
if(i < 110)
goto ADD;
printf("sum = %d\n", sum);
}
-----------------------------------------------------------------------------------------------------------------1. First, predict the output of the following C program. Then, replace both of the goto statements
with other valid C statements. (Note: goto statement is similar to an unconditional jump in
assembly programming; i.e. the next statement executed after a goto LABEL statement is the
statement that has been labeled by LABEL.)
#include
void main(void){
int sum = 0, i = 0;
for(; i < 25;i++)
if(i & 2)
goto PRINT;
else
ADD: sum += i;
PRINT: printf("i = %d\n", i);
if(i < 35)
goto ADD;
printf("sum = %d\n", sum);
}
2. Nested for-loops: Consider the following two-D array of integers in C++:
int array[50][75];
Initialize every element of the array array[i][j] with a value equal to i+j
a. In row major, from top to bottom, and left to right
b. In column major, from right to left, and from top to bottom.
c. In column major, from left to right, and from bottom to up.
d. In row major, from bottom to top and right to left
3. Answer the following questions:
a. (25 points) Write a program in Java that stores the first name (String), last name (String),
score (int), and ID (int) of the following 10 students in an array of objects from class
Student:
Sophia Miller: 90, 1235
James Davis: 83, 1235
Ava Garcia: 87, 1235
John Smith: 85, 1234
Emma Johnson: 92, 1234
Michael Williams: 78, 1234
Olivia Brown: 88, 1234
William Jones: 95, 1234
Logan Martinez: 89, 1235
Charlotte Hernandez: 91, 1236
The program must then sort the list (Student class must be comparable!) and print out the
students information on the console. Finally, the program must store all students in a hash
table, remove students with repeated IDs, and print the remaining students on the
console.
b. (25 points) Repeat the same program in C#, C++, or Python (your choice).
c. (10 points) Discuss the similarities and differences of object-oriented programming
languages by comparing the answers to parts a and b.
Hint#1: Java/C# has an interface called
"Comparable"/"IComparable" that can be implemented by defining
the "compareTo"/"CompareTo" method. Classes implementing this interface can be
sorted by the method "Arrays.sort"/"Arrays.Sort".
Hint#2: Java/C# requires the class Student to override the "equals"/"Equals" and
"hashCode"/"GetHashCode" methods of Object class if objects of this class need to be
stored in a set made of hash tables.
Hint#3: Java/C# requires the class Student to override the "toString"/"ToString" method
of the Object class if objects of this class need to be converted to a string to be presented
on the console.