0% found this document useful (0 votes)
5 views3 pages

Sec A Lab Quiz 3

This document is a quiz for a programming fundamentals lab course, specifically focusing on C++ code using arrays of pointers. It includes a coding task to find the statistics of an array, such as maximum, minimum, sum, and average values. The code provided demonstrates how to implement these calculations within a structured format.

Uploaded by

mashnabsafdar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Sec A Lab Quiz 3

This document is a quiz for a programming fundamentals lab course, specifically focusing on C++ code using arrays of pointers. It includes a coding task to find the statistics of an array, such as maximum, minimum, sum, and average values. The code provided demonstrates how to implement these calculations within a structured format.

Uploaded by

mashnabsafdar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

CL-1002 Programming Fundamentals - Lab (CE) / SEC A / Spring’25 / -Quiz 03 / LLO-03

28/04/2025 Marks: 10/ Time: 20 min


Name: ____Muhammad Ashnab Safdar________ Roll No: _I24-6500__ Section: _CE-A___

Note: After Completing quiz, you should submit this MS word file on GCR

Q1. Using array of pointers, write C++ code to find stats of array according to the given output.

CODE:
#include <iostream>
using namespace std;

struct input {
int arr[10];
};

void stats(int arr[]) {


int max = arr[0];
int min = arr[0];
int sum = 0;
float avg = 0;
int m_max=0;
int m_min=0;

// Find max and min


for (int i = 0; i < 10; i++) {
Page 1 of 3
CL-1002 Programming Fundamentals - Lab (CE) / SEC A / Spring’25 / -Quiz 03 / LLO-03
28/04/2025 Marks: 10/ Time: 20 min
Name: ____Muhammad Ashnab Safdar________ Roll No: _I24-6500__ Section: _CE-A___

if (arr[i] > max) {


max = arr[i];
m_max=i;}
if (arr[i] < min) {
min = arr[i];
m_min=i;
}
sum += arr[i]; // add to sum
}

avg = (float)sum / 10; // calculate average

cout << "Maximum Value: " << max <<"at the index "<< m_max<< endl;
cout << "Minimum Value: " << min <<"at the index "<<m_min<< endl;
cout << "Sum of Array: " << sum << endl;
cout << "Average of Array: " << avg << endl;
}

int main() {
int i = 0;
input* entry = new input; // object created for struct input
cout << "Enter array elements: " << endl;
for (i = 0; i < 10; i++) {
cout << "Enter element " << i << ": ";
cin >> entry->arr[i];
}

stats(entry->arr); // pass the whole array

delete entry; // good practice to free memory


return 0;
}

Page 2 of 3
CL-1002 Programming Fundamentals - Lab (CE) / SEC A / Spring’25 / -Quiz 03 / LLO-03
28/04/2025 Marks: 10/ Time: 20 min
Name: ____Muhammad Ashnab Safdar________ Roll No: _I24-6500__ Section: _CE-A___

Page 3 of 3

You might also like