0% found this document useful (0 votes)
7 views6 pages

Lab 11 & 12

The document contains the code for 3 programs: 1) A program that takes a string as input and calculates its length. It displays the length. 2) A program that combines two strings without using built-in string functions. It takes two strings as input and displays the combined string. 3) A program that takes test scores as input, sorts them in ascending order, calculates the average, and displays the sorted scores and average. It uses functions to sort and calculate the average.

Uploaded by

Irtaza Ali Nasir
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)
7 views6 pages

Lab 11 & 12

The document contains the code for 3 programs: 1) A program that takes a string as input and calculates its length. It displays the length. 2) A program that combines two strings without using built-in string functions. It takes two strings as input and displays the combined string. 3) A program that takes test scores as input, sorts them in ascending order, calculates the average, and displays the sorted scores and average. It uses functions to sort and calculate the average.

Uploaded by

Irtaza Ali Nasir
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/ 6

2020

LAB # 11

REG # 200901099
SUBMITTED BY:IRTAZA ALI NASIR

SUBMITTED TO | SIR ASAD


Q.1 Write a program that takes an array large enough to hold a user-defined
number of test scores. Once all the scores are entered, the array should be
passed to a function that sorts them in ascending order. Another function
should be called that calculates the average score. The program should
display the sorted list of scores and averages with appropriate headings.

ASSINGED PROGRAM

#include<iostream>
using namespace std;
int main() {
char irt[100], * pt;
int i = 0;

cout << " ENTER A STRING "<< endl;


gets_s(irt);
pt = irt;
while (*pt != '\0') {
i++;
pt++;
}
cout << "SIZE OF STRING: " << i;

return 0;
}

RESULT ON SECREEN

3. Write a program to combine two string by using pointer without using any built-
in function of strings..
ASSINGED PROGRAM

#include <iostream>

using namespace std;


int main() {

char str1[20], str2[20];


char* s1 = str1;
char* s2 = str2;

cout << "ENTER FIRST STRING "<< endl;


cin >> str1;
cout << "EENTER SECOND STRING " << endl;
cin >> str2;

while (*(++s1));

while (*(s1++) = *(s2++));

cout << "COMBINED STRING" << endl << str1;

return 0;

RESULT ON SECREEN

Q.3 Write a program that takes an array large enough to hold a user-defined
number of test scores. Once all the scores are entered, the array should be
passed to a function that sorts them in ascending order. Another function
should be called that calculates the average score. The program should
display the sorted list of scores and averages with appropriate headings.
ASSINGED PROGRAM
#include <iostream>
using namespace std;
void sorting(int arr[20], int n) {
int temp = 0;
for (int i = 0;i < n;i++)
{
for (int j = i + 1;j < n;j++)
{
if (arr[i] > arr[j])
{
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
cout << " Ascending Order " << endl;
for (int i = 0;i < n;i++)
cout << arr[i] << endl;
cout << endl;
}
void average(int arr[20], int n)

{
int sum = 0;
int avg = 0;
for (int i = 0; i < n; i++)
{
sum += arr[i];
}
avg = sum / n;
cout << " AVERAGE " << endl << avg;
}

int main()
{
int arr[20];
int n = 0, temp = 0, avg = 0;

cout << "ENTER TOTAL NUMBER OF SCORES: " << endl << endl << " NOTE : YOU CANNOT
PUT MORE THEN 20 SCORES" << endl << endl;
cin >> n;

if (n < 0 || n>20)
{
cout << "INVALID VALUE PLZ READ NOTE CAREFULLY AND TRY AGAIN" << endl;

}
else
{
for (int i = 0;i < n;i++)
{
cout << "ENTER SCORE " << i + 1 << " : ";
cin >> arr[i];
}
}
sorting(arr, n);
average(arr, n);
}

RESULT ON SECREEN

You might also like