You are on page 1of 6

Laboratory Report 4

GRAPHS, SEARCHING, AND SORTING


Name: Tusi, Kevin Angelo M. Date: 02-03-24
Program: CPE Section: E01

A. Instructions:
(Please include the following: 1. Screenshots of the output from MindTap, 2. Screenshots of the IDE from
MindTap, and 3. The source code from MindTap.)

Screenshot of Output
(Insert images here from the output of the console window of MindTap)

Resize the image if necessary.

Screenshot of Codes
(Insert images here)

Screenshot of your code in MindTap. Use the snipping tool to properly capture the codes.

Resize the image properly so that it fits in the table. Use a whole page for this part if necessary.

Source Code
(insert Source Code here)

Paste the actual code from MindTap here. Use the following format: Courier New 9

#include <iostream>

using namespace std;

int main() {
cout << "Hello World" << endl;
return 0;
}

_________________________________________________________________________________________________
CPE104L Data Structures and Algorithms
School of Electrical, Electronics, and Computer Engineering Page | 1
Laboratory Report 4
GRAPHS, SEARCHING, AND SORTING

_________________________________________________________________________________________________
CPE104L Data Structures and Algorithms
School of Electrical, Electronics, and Computer Engineering Page | 2
Laboratory Report 4
GRAPHS, SEARCHING, AND SORTING
B. Coding Exercises:
1. Write a program that outputs the shortest distance from a given node to every other node in the graph.

Screenshot of Output

Screenshot of Codes

Source Code
main.cpp
#include <iostream>
#include "searchSortAlgorithms.h"

using namespace std;

int main() {
const int length = 7;
int sortedArray[length] = {1, 3, 5, 7, 9, 11, 13};

int itemToSearch;
cout << "Enter the item to search: ";
cin >> itemToSearch;

int result = seqOrdSearch(sortedArray, length, itemToSearch);

if (result == -1) {
cout << "Item not found in the array." << endl;
} else {
cout << "Item found at index " << result << "." << endl;
}

return 0;
}
// SEARCH_SORT_ALGORITHMS_H
#ifndef SEARCH_SORT_ALGORITHMS_H
#define SEARCH_SORT_ALGORITHMS_H

template<class elemType>
inline int seqOrdSearch(const elemType list[], int length, const elemType& item)
{
_________________________________________________________________________________________________
CPE104L Data Structures and Algorithms
School of Electrical, Electronics, and Computer Engineering Page | 3
Laboratory Report 4
GRAPHS, SEARCHING, AND SORTING
int index = 0;

// Loop until the end of the list or the item is found


while (index < length && list[index] < item) {
index++;
}

// Check if the item is found


if (index < length && list[index] == item) {
return index; // Item found at index
} else {
return -1; // Item not found
}
}

#endif // SEARCH_SORT_ALGORITHMS_H

2. Write a program to test the function you designed in Exercise 3. Note: Have the function,seqOrdSearch,
return -1 if the item is not found in the list. (return the index of the item if found).

Screenshot of Output

Screenshot of Codes

Source Code

_________________________________________________________________________________________________
CPE104L Data Structures and Algorithms
School of Electrical, Electronics, and Computer Engineering Page | 4
Laboratory Report 4
GRAPHS, SEARCHING, AND SORTING
C. Findings, Observations, and Comments:
Guiding Questions :
1. Did you solve the coding exercise/s?
2. Are there any difficulties during coding or set-up that you encountered?
3. What are your findings, observations, and comments in the coding exercise?

I’m able to solve the lab 4-2 but the lab 4-1 I had a hard time solving it and I couldn’t find the error.
The main exercise is hard by it self but I’m able to solve it and got 100%. I learned the sort algorithm
that we discussed last meeting and I’m able to apply it to this laboratory exercise.

_________________________________________________________________________________________________
CPE104L Data Structures and Algorithms
School of Electrical, Electronics, and Computer Engineering Page | 5
Laboratory Report 4
GRAPHS, SEARCHING, AND SORTING
D. Score Sheet

Poor Fair Good Excellent


Criteria Score
(25%) (50%) (75%) (100%)
The report was The report was The report was The report was
incomplete, complete, complete, neat, complete, neat,
I. Completeness,
messy, and had messy, and had and had 1 or 2 and all the
Documentation, and
many many unanswered questions had
Organization of Report
unanswered unanswered questions. been answered.
questions. questions.
The program The program The program The program
had had corrected had corrected had appropriate
inappropriate indention, but indention, elements and
elements and inappropriate adequate structures,
II. Coding Design and
structures, elements and program correct
Patterns
incorrect structures and documentation, indention, and
indention, and poor program but inappropriate excellent
poor program documentation. elements and program
documentation. structures. documentation.
The findings. The findings. The findings. The findings.
observations, observations, observations, observations,
and comments and comments and comments and comments
were not based based on the were based on were based on
on the gathered gathered data the gathered the gathered
III. Findings, Observations, data and results. and results but data and results data and results
and Comments All thoughts were not and were mostly and were
were elaborated. Not elaborated. Most completely
inconsistent and all thoughts were of the thoughts elaborated. All
unclear. consistent and were consistent the thoughts
clear. and clear. were consistent
and clear.
The words used The words used The words used The words used
were were were were
inappropriate, appropriate; appropriate, had appropriate, had
IV. Grammar and wrong grammar however, bad proper grammar proper grammar
Composition usage, and poor grammar and usage, but poor usage, and
sentence poor sentence sentence excellent
construction was construction construction was sentence
observed. were observed. observed. construction.

SCORE:

CHECKED
Signature
Rating
Date

_________________________________________________________________________________________________
CPE104L Data Structures and Algorithms
School of Electrical, Electronics, and Computer Engineering Page | 6

You might also like