C++ Programming: From Problem Analysis to Program Design
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN: 9781337102087
Author: D. S. Malik
Publisher: Cengage Learning
Expert Solution & Answer
Book Icon
Chapter 12, Problem 17SA

Explanation of Solution

The program has been explained in the in-lined comments:

#include <iostream> 

using namespace std; 

int main()  

{  

    //delcare a list and initialize it

    //with an array of 6 elements 

    int numList[6] = {25, 37, 62, 78, 92, 13};

    //create a pointer to the list -

    //the base address of the list is assigned

    //to the pointer

    int *listPtr = numList;

    //a new pointer is declared and is assigned

    //an address 2 int positions incremented i.e

    //it points to the 3rd position in the array

    //or numlist[2] which is the value 62

    int *temp = listPtr + 2;

    //declare an int variable

    int num;

    //assign value of the memory address pointed to

    //by listPtr with the arithmetic expression on the

    //RHS of the assignment operator

    //RHS = *(listPtr + 1) - *listPtr = 

    //numList[1] - numList[0] = 37-25 = 12

    //since listPtr is numList[0] so now the array elements

    //are {12, 37, 62, 78, 92, 13}

    *listPtr = *(listPtr + 1) - *listPtr;

    //listPtr is incremented and now points to numList[1]

    // i.e. 37

    listPtr++;

    //num is assigned the value pointed to by temp which is

    //numList[2] i.e. 62

    num = *temp;

    //temp is incrementedand now points to numList[3] 

    //i...

Blurred answer
Students have asked these similar questions
#include <stdio.h>#include <stdlib.h>#include <time.h> struct treeNode {  struct treeNode *leftPtr;  int data;  struct treeNode *rightPtr;}; typedef struct treeNode TreeNode;typedef TreeNode *TreeNodePtr; void insertNode(TreeNodePtr *treePtr, int value);void inOrder(TreeNodePtr treePtr);void preOrder(TreeNodePtr treePtr);void postOrder(TreeNodePtr treePtr); int main(void) {  TreeNodePtr rootPtr = NULL;   srand(time(NULL));  puts("The numbers being placed in the tree are:");   for (unsigned int i = 1; i <= 10; ++i) {    int item = rand() % 15;    printf("%3d", item);    insertNode(&rootPtr, item);  }   puts("\n\nThe preOrder traversal is: ");  preOrder(rootPtr);   puts("\n\nThe inOrder traversal is: ");  inOrder(rootPtr);   puts("\n\nThe postOrder traversal is: ");  postOrder(rootPtr);} void insertNode(TreeNodePtr *treePtr, int value) {  if (*treePtr == NULL) {    *treePtr = malloc(sizeof(TreeNode));     if (*treePtr != NULL) {      (*treePtr)->data = value;…
Exercise, maxCylinderVolume F# system function such as min or methods in the list module such as List.map are not allowed Write a function maxCylinderVolume that takes a list of floating-point tuples that represent dimensions of a cylinder and returns the volume of the cylinder that has the largest volume. Each tuple has two floating point values that are both greater than zero. The first value is the radius r and the second value is the height h. The volume of the cylinder is computed using ??2h. The value π is represented in F# with System.Math.PI. If the list is empty, return 0.0. Examples: > maxCylinderVolume [(2.1, 3.4); (4.7, 2.8); (0.9, 6.1); (3.2, 5.4)];;val it : float = 194.3137888> maxCylinderVolume [(0.33, 0.66)];;val it : float = 0.2257988304
#include <stdio.h>#include <string.h>#define SIZE 6struct Student{char name[50];int id;float mark;};int Search1(char input[], struct Student data[]);int Search2(int input, struct Student data[]);int main() {char search_name[30];int search_id;int result1, result2;struct Student list[SIZE] = {{"Amylia", 544199, 75.4},{"Cheong", 143566, 92.3},{"Harry", 109774, 65.5},{"Krishnan", 334514, 86.7},{"Melissa", 257890, 55.4},{"Timothy",144656, 77.8}};printf("Enter Student Name: ");gets(search_name);result1 = Search1(search_name, list);//Answer for part (a)(ii) – Display the matching index of result1printf("Enter Student ID: ");scanf("%d",&search_id);result2 = Search2(search_id,list);//Answer for part (a)(iii)- Display the matching index of result2return 0;}//Answer for part (a)(i) – function definition for Search1//Answer for part (a)(iii) – function definition for Search2
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education