0% found this document useful (0 votes)
15 views

Assignment 12

The document contains 5 programs that use arrays in C++. The programs include inputting student marks into an array and displaying the number of students in each grade, finding the minimum and maximum values in an array, calculating total bill prices using 3 arrays, and displaying values greater than the average in an array. The programs demonstrate passing arrays to functions and using arrays to store and manipulate data.

Uploaded by

f21bscs008
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)
15 views

Assignment 12

The document contains 5 programs that use arrays in C++. The programs include inputting student marks into an array and displaying the number of students in each grade, finding the minimum and maximum values in an array, calculating total bill prices using 3 arrays, and displaying values greater than the average in an array. The programs demonstrate passing arrays to functions and using arrays to store and manipulate data.

Uploaded by

f21bscs008
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/ 12

ASSIGNMENT - 12

Course name : Programming Fundamental


Department : Software Engineering
Submitted by : Zara Khush Bakhat
Submitted to : Ms Aasma Akram
Submitted on : 10 - March - 2023
1. Program that input marks of 10 students in an array program display no of student
in each grade according to their criteria.
#include <iostream>

using namespace std;

int main()

int marks[10];

int gradeA = 0, gradeB = 0, gradeC = 0, gradeD = 0, gradeF = 0;

cout << "Enter the marks of 10 students:\n";

for (int i = 0; i < 10; i++)

cin >> marks[i];

for (int i = 0; i < 10; i++) {

if (marks[i] >= 90)

gradeA++;

else if ((marks[i] >= 80) &&( marks[i] < 90) )

gradeB++;

else if ((marks[i] >= 70 )&& (marks[i] < 80) )

gradeC++;

else if ((marks[i] >= 60 )&& (marks[i] < 70) )

gradeD++;

else

gradeF++;
}

cout << endl<<"Number of students in each grade:"<<endl;

cout << "How many student got A Grade : " << gradeA << endl;

cout << "How many student got B Grade: " << gradeB << endl;

cout << "How many student got C Grade: " << gradeC << endl;

cout << "How many student got D Grade: " << gradeD << endl;

cout << "How many student got F Grade: " << gradeF << endl;

return 0;

2. Write a program that stores 10 values in an array and display minimum no from
array and show on screen.

#include<iostream>

using namespace std;

int main()

int a[10] , min = 0 , i;

cout<<" enter "<<endl;

for( i = 0 ; i<10 ; i++)

cin>> a[i];

min = a[i];

for (i = 0 ; i < 10 ; i++)

if ( a[i]< min)

min = a[i];
}

cout<<" The minimun value in an array is = "<< min<<endl;

return 0;

3. Write a program that stores 10 values in an array and display maximum no from
array and show on screen
#include<iostream>

using namespace std;

int main()

int a[10] , max = 0 , i;

cout<<" enter "<<endl;

for( i = 0 ; i<10 ; i++)

cin>> a[i];

max = a[i];

for (i = 0 ; i < 10 ; i++)

if ( a[i]> max)

max = a[i];

cout<<" The maximum value in an array is = "<< max<<endl;

return 0;

4. Write a program that use 3 arrays in c++ of book, notebooks and pencil by user and
display calculate total bill price of one notebook is 150 Rs, price of one book is 150
and price of one pencil is 50 by using array in c++.
#include<iostream>

using namespace std;

int main()

int q[ 3] , i;

string n[3]= { "Books "," Notebooks ", " Pencil"};

int pr[3] = { 150 , 150 , 50};

int total_bil =0;

for ( i = 0 ; i<3 ; i++)

cout<< " Enter quantity "<< n[i]<< " = ";

cin>> q[i];

for ( i = 0 ; i<3 ; i++)

pr[i] *=q[i];

total_bil +=pr[i];

cout<< endl<<" The total_ bil is = "<< total_bil<<endl;

return 0;

5. Write a program that input 10 floating number in an array. It displays value which
are greater than average value in an array.
#include<iostream>

using namespace std;

int main()

float a[10], avg =0, sum =0 , g =0;

int i;
for(i =0 ; i<10 ; i++)

cin>> a[i];

for(i = 0 ; i<10 ; i++)

sum += a[i];

avg = sum /10;

for(i = 0 ; i<10 ; i++)

if (a[i]> avg)

g = a[i];

cout<< " The greater number then avg value in an array is = "<< g <<endl;

return 0;

Array pass by Functions


1. Program that input marks of 10 students in an array program display no of student in
each grade according to their criteria.

#include <iostream>

using namespace std;

int st(int m[10] , int size)

int gradeA = 0, gradeB = 0, gradeC = 0, gradeD = 0, gradeF = 0;

for (int i = 0; i < 10; i++) {

if (m[i] >= 90)

gradeA++;
else if ((m[i] >= 80) &&( m[i] < 90) )

gradeB++;

else if ((m[i] >= 70 )&& (m[i] < 80) )

return gradeC++;

else if ((m[i] >= 60 )&& (m[i] < 70) )

gradeD++;

else

gradeF++;

cout << endl<<"Number of students in each grade:"<<endl;

cout << "How many student got A Grade : " <<gradeA << endl;

cout << "How many student got B Grade: " << gradeB << endl;

cout << "How many student got C Grade: " << gradeC << endl;

cout << "How many student got D Grade: " << gradeD << endl;

cout << "How many student got F Grade: " << gradeF << endl;

int main()

int marks[10];

cout << "Enter the marks of 10 students:\n";

for (int i = 0; i < 10; i++)

cin >> marks[i];


}

st(marks ,10);

return 0;

2. Write a program that stores 10 values in an array and display minimum no from array
and show on screen.

#include<iostream>

using namespace std;

int mi(int m[10] , int size )

int min ;

min = m[0];

for (int i = 0 ; i < 10 ; i++)

if ( m[i]< min)

min = m[i];

cout<<" The minimun value in an array is = "<< min<<endl;

int main()

int a[10] , mimm = 0;

cout<<" enter "<<endl;

for( int i = 0 ; i<10 ; i++)


{

cin>> a[i];

mi(a , 10);

return 0;

3. Write a program that stores 10 values in an array and display maximum no from array
and show on screen.

#include<iostream>

using namespace std;

int mi(int m[10] , int size )

int min ;

min = m[0];

for (int i = 0 ; i < 10 ; i++)

if ( m[i]< min)

min = m[i];

cout<<" The minimun value in an array is = "<< min<<endl;

int main()

int a[10] , mimm = 0;


cout<<" enter "<<endl;

for( int i = 0 ; i<10 ; i++)

cin>> a[i];

mi(a , 10);

return 0;

4. Write a program that use 3 arrays in c++ of book, notebooks and pencil by user and
display calculate total bill price of one notebook is 150 Rs, price of one book is 150 and
price of one pencil is 50 by using array in c++.

#include<iostream>

using namespace std;

int bil(int qu[],string na[] , int p[], int size )

int total_bil =0;

for (int i = 0 ; i<3 ; i++)

p[i] *=qu[i];

total_bil +=p[i];

cout<< endl<<" The total_ bil is = "<< total_bil<<endl;

int main()

int q[ 3] , i;

string n[3]= { "Books "," Notebooks ", " Pencil"};


int pr[3] = { 150 , 150 , 50};

for ( i = 0 ; i<3 ; i++)

cout<< " Enter quantity "<< n[i]<< " = ";

cin>> q[i];

bil(q , n , pr , 3);

return 0;

5. Write a program that input 10 floating number in an array. It displays value which are
greater than average value in an array.

#include<iostream>

using namespace std;

float gr(float b[] , int size)

float avg =0, sum =0 , g =0;

for(int i = 0 ; i<10 ; i++)

sum += b[i];

avg = sum /10;

for(int i = 0 ; i<10 ; i++)

if (b[i]> avg)

g = b[i];

}
cout<< " The greater number then avg value in an array is = "<< g <<endl;

int main()

float a[10];

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

cin>> a[j];

gr(a , 10);

return 0;

You might also like