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

pflab4

The document contains programming assignments for a course on Programming Fundamentals at the University of Sialkot, Pakistan. It includes five programming tasks that involve inputting integers, counting prime numbers, managing student roll numbers and marks, calculating employee salaries and taxes, and counting occurrences of numbers in an array. Each task is accompanied by C++ code implementations and expected results.

Uploaded by

rananaveed595
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

pflab4

The document contains programming assignments for a course on Programming Fundamentals at the University of Sialkot, Pakistan. It includes five programming tasks that involve inputting integers, counting prime numbers, managing student roll numbers and marks, calculating employee salaries and taxes, and counting occurrences of numbers in an array. Each task is accompanied by C++ code implementations and expected results.

Uploaded by

rananaveed595
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

University of Sialkot,Pakistan

Assignment no. 4

Subject: PROGRAMMING
FUNDAMENTALS LAB

NAME: JOVARIYA GULZAR

ROLL NUMBER: 054

DATE: 13-3-25

DEPARTMENT: BSCS GREY

SEMESTER: 1
Q-1. Write a program that inputs ten integers in an array and counts all
prime numbers entered by the user. The program finally displays total
number of primes in array.

#include <iostream>
using namespace std;

int main()
{
int a[10],count=0,p;
cout<<"Enter 10 integers: "<<" ";
for(int i=0; i<10; i++)
{
cin>>a[i];
}
for(int i=0; i<10; i++)
{
int num=a[i];
p=1;
for(int c=2; c<=num/2; c++)
{
if(num%c==0)
{
p=0;
break;
}
}
if(p==1)
count++;
}
cout<<"\nTotal prime numbers in the Array : "<<count<<endl;
return 0;
}
Result:
Q-2 Write a program that uses two arrays to store the roll number and marks
of student. roll numbers and marks elements of the arrays. (For example, if
roll number 1 is stored in mo[0] then his marks must be stored in marks[0]
and so on.) The program finally displays the roll number and marks of the
student with highest marks.

#include <iostream>
using namespace std;

int main()
{
int rollno[5] = {54, 76, 89, 60, 61};
int marks[5] = {85, 90, 78, 92, 88};

int maxindx= 0;
for (int i = 1; i < 5; i++) {
if (marks[i] > marks[maxindx]) {
maxindx = i;
}
}
cout<<"Student with highest marks: "<<endl;
cout << "Roll Number: " << rollno[maxindx] << "\nMarks: " << marks[maxindx] <<
endl;
return 0;

}
Result:

Q-3Write a program that uses four arrays named numbers, squares, cubes
and sums each having ten elements. The numbers array stores the values of its
indexes, the squares array stores the squares of its indexes, the cubes array
stores the cubes of its indexes and sums array stores the sum of corresponding
indexes of three arrays. The program should display the values of sums array
and the total of all values in sums array.
#include <iostream>
using namespace std;

int main()
{
int numbers[10], squares[10], cubes[10], sums[10];
int total= 0;
for (int i = 0; i < 10; i++) {
numbers[i] = i;
squares[i] = i * i;
cubes[i] = i * i * i;
sums[i] = numbers[i] + squares[i] + cubes[i];
total=total + sums[i];
}

cout << "Sums array values:" << endl;


for (int i = 0; i < 10; i++) {
cout << sums[i] << " ";
}
cout << "\nTotal sum: " << total << endl;
return 0;
}
Result:

Q-4. Write a program that inputs the names and monthly salaries of 5
employees. The program checks annual salary of each person. If annual salary
is greater than or equal to Rs 2,50000/- then it prints name, salary and a
message "Tax to be paid' else it prints name, salary and a message 'No tax'.

#include <iostream>
using namespace std;

int main()
{
int n[5];
string name[5];
float salary[5];
int anualS;
for(int i=0; i<5; i++)
{
cout<<"Enter name of employee: ";
cin>>name[i];
cout<<"Enter monthly salary of "<<name[i]<<": ";
cin>>salary[i];

}
cout << "\nEmployee Salary Details:\n";
for (int i = 0; i < 5; i++) {
anualS = salary[i] * 12;
cout << "Name: " << " Annual Salary of " <<name[i]<<": "<< anualS;
if (anualS >= 250000) {
cout << " - Tax to be paid";
} else {
cout << " - No tax";
}
cout << endl;
}
return 0;
}
Result:

Q5. Write a program that inputs ten integers in an array. It displays the
number of occurrences of each number in the array as follows:
3 is stored 4 times in the array.
1 is stored 1 times in the array.
#include <iostream>
using namespace std;

int main()
{
int numbers[10], count[10]={0};

cout << "Enter 10 integers: ";


for (int i = 0; i <10; i++) {
cin >> numbers[i];
}

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


int occurrences = 1;
if (count[i] == -1) continue;
for (int j = i + 1; j <10; j++) {
if (numbers[i] == numbers[j]) {
occurrences++;
count[j] = -1;
}
}
cout << numbers[i] << " is stored " << occurrences << " times in the array." << endl;
}
return 0;
}
Result:

You might also like