EBK DATA STRUCTURES AND ALGORITHMS IN C
EBK DATA STRUCTURES AND ALGORITHMS IN C
4th Edition
ISBN: 9781285415017
Author: DROZDEK
Publisher: YUZU
Expert Solution & Answer
Book Icon
Chapter 1, Problem 4E

Explanation of Solution

a)

Function using Pointers:

The following program demonstrates to take an integer array and adds all elements of the array.

Program:

//Select header files

#include <stdio.h>

#include<iostream>

using namespace std;

//Main function

int main()

{

  //Integer array declaration

  static int array[5] = { 200, 400, 600, 800, 1000 };

  //Declaration of variables

  int sum;

  //Function for addition

  int addnum(int *ptr);

  // Store values into variable

  sum = addnum(array);

  //Display result

  cout<< "Sum of all array elements ="<<sum<<"\n";

  return 0;

}

Create the function “addnum()” which is used to add integers given in an integer array...

Explanation of Solution

b)

This program takes an integer array and removes all odd elements of array and displays only even elements of the array, the complete program code is shown below:

Program:

//Select header files

#include <iostream>

using namespace std;

//Declare the integer array with values

int ordArray[10] = {21,22,23,24,25,26,27,28,29,30};

int ordArray1[10];

In this construct, a pointer is declared which points to the given integer array. The function declaration is provided and values obtained are been pointed by an integer pointer and finally contents of array is been displayed.

//Main function

int main()

{

  //Pointer to ordered array is created

  int* ordArrayPtr = ordArray;

Declare the function “removeodd()” to remove odd numbers is been provided and then the values returned by the function are been pointed by an integer pointer

  // Function to remove odd numbers

  int* removeOddd(int* ordArrayPtr);

  // Store the value in integer pointer

  int* abc = removeOddd(ordArrayPtr);

Execute for loop to display the integer values present in the array which denotes the final result.

/*Display array values through for loop and loop until “j” value is less than 5*/

  for ( int j=0; j < 5; j++ )

  cout << *(abc + j) << endl;

  //Console window is kept alive after the execution

  cin.get();

  return 0;

}

This function takes an integer array and removes all odd numbers from the array and displays only even numbers present in the array. It checks for each element in the array by iterating over array using loop and it displays the value only if it is an even number...

Explanation of Solution

Reason:

In the above case, it would be Not Easier if the array were unordered

Blurred answer
Students have asked these similar questions
Whentheuserenters!!,themostrecentcommandinthehistoryisexecuted.In the example above, if the user entered the command: Osh> !! The ‘ls -l’ command should be executed and echoed on user’s screen. The command should also be placed in the history buffer as the next command. Whentheuserentersasingle!followedbyanintegerN,theNthcommandin the history is executed. In the example above, if the user entered the command: Osh> ! 3 The ‘ps’ command should be executed and echoed on the user’s screen. The command should also be placed in the history buffer as the next command. Error handling: The program should also manage basic error handling. For example, if there are no commands in the history, entering !! should result in a message “No commands in history.” Also, if there is no command corresponding to the number entered with the single !, the program should output "No such command in history."
Activity No. Activity Time (weeks) Immediate Predecessors 1 Requirements collection 3 2 Requirements structuring 4 1 3 Process analysis 3 2 4 Data analysis 3 2 5 Logical design 50 3,4 6 Physical design 5 5 7 Implementation 6 6 c. Using the information from part b, prepare a network diagram. Identify the critical path.
2. UNIX Shell and History Feature [20 points] This question consists of designing a C program to serve as a shell interface that accepts user commands and then executes each command in a separate process. A shell interface gives the user a prompt, after which the next command is entered. The example below illustrates the prompt osh> and the user's next command: cat prog.c. The UNIX/Linux cat command displays the contents of the file prog.c on the terminal using the UNIX/Linux cat command and your program needs to do the same. osh> cat prog.c The above can be achieved by running your shell interface as a parent process. Every time a command is entered, you create a child process by using fork(), which then executes the user's command using one of the system calls in the exec() family (as described in Chapter 3). A C program that provides the general operations of a command-line shell can be seen below. #include #include #define MAX LINE 80 /* The maximum length command */ { int…
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:9781305503922
Author:Patrick M. Carey
Publisher:Cengage Learning