Prepare for your exams

Study with the several resources on Docsity

Earn points to download

Earn points by helping other students or get them with a premium plan

Guidelines and tips

Prepare for your exams

Study with the several resources on Docsity

Earn points to download

Earn points by helping other students or get them with a premium plan

Community

Ask the community

Ask the community for help and clear up your study doubts

University Rankings

Discover the best universities in your country according to Docsity users

Free resources

Our save-the-student-ebooks!

Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors

A collection of solved C++ programming exercises for students studying computer science. Each exercise focuses on key programming concepts, problem-solving, and demonstrating the output when program is executed. 1. Search an Integer: Develop a C++ program to search for a specific integer within a list. 2. Counting Sales: Create a program to count the number of sales made by a salesman. 3. Grading Students based on Marks: Implement a program that accepts the marks of different subjects entered by the user and calculates the grade for each student based on defined criteria. 4. Matrix Equality Check: Write a program that takes the number of rows and columns as input, followed by the elements of two matrices, and determines whether the matrices are equal. 5. Transpose of a Matrix: Design a program to compute the transpose of a matrix. 6. Diagonal Elements of Matrix: Develop a program that accepts elements of a matrix as input and outputs only the left and right diagonal elements.

Typology: Exercises

2023/2024

1 / 13

Download C++ Programming Exercises for High School Students: Solved Problems and more Exercises Computer science in PDF only on Docsity! Search Integer #include<iostream.h> #include<conio.h> void main() { clrscr(); int a[10],n; cout<<"Enter the number you want to search\n"; cin>>n; cout<<"Enter the array elements:\n"; for(int i=0; i<10; i++) cin>>a[i]; for(i=0; i<10; i++) { if(a[i]==n) cout<<"The element "<<n<<" exist at "<<i+1<<" position\n"; } getch(); } Output Salesmen #include<iostream.h> #include<conio.h> void main() { clrscr(); float sales[5][3], total_sales; cout<<"Enter the sales of 5 salesman\n"; for(int i=0; i<5; i++) { total_sales=0; cout<<"Enter the sales of salesman "<<i+1<<endl; for(int j=0; j<3; j++) { cin>>sales[i][j]; total_sales=total_sales+ sales[i][j]; } cout<<"The total sales of a salesman "<<i+1<<" = "<<total_sales<<endl; } getch(); } Enter the marks of three subjects of studenti
90
90
90
Enter the marks of three subjects of studentz
90
90
90
Enter the marks of three subjects of student3
Enter the marks of three subjects of student2
930
be 10)
bs 10)
Enter the marks of three subjects of student3
be 10)
10)
be]
Enter the marks of three subjects of student4
i 10)
90.
be 10)
Studenti
kee U Me ho cere!
Grade=A
StudentzZ
Total marks=270
Grade=A
Student3
Total marks=270
Grade=A
Student4
Total marks=270
Grade=A
Equality #include<iostream.h> #include<conio.h> void main() { clrscr(); int a[50][50], b[50][50], n, flag=0; cout<<"Enter the number of rows and columns:\n"; cin>>n; cout<<"Enter the array elements of matrix a:\n"; for(int i=0; i<n; i++) for(int j=0; j<n; j++) cin>>a[i][j]; cout<<"Enter the array elements of matrix b:\n"; for(i=0; i<n; i++) for(j=0; j<n; j++) cin>>a[i][j]; for(i=0; i<n; i++) { for(int j=0; j<n; j++) { if(a[i][j]!=b[i][j]) { flag=1; break; } } if(flag==1) break; } if(flag==1) cout<<"The matrices are not equal\n"; else cout<<"The matrices are equal\n"; getch(); } Output
Enter the number of rows and colums:
3
Enter the array elements of matrix a:
nmter the array elements of matrix b:
i
fe
5
is)
ra
8
2
1
3
1D
i)
fe
5
The matrices are not equal
getch();
Output
Enter the number of rows and columns:
3
Enter the array elements:
:
3
i
a
is)
a
8
be)
2
The left diagonal:
FA
is)
Right Diagonal #include<iostream.h> #include<conio.h> void main() { clrscr(); int a[50][50], n; cout<<"Enter the number of rows and columns:\n"; cin>>n; cout<<"Enter the array elements:\n"; for(int i=0; i<n; i++) { for(int j=0; j<n; j++) cin>>a[i][j]; } cout<<"The right diagonal:\n"; for(i=0; i<n; i++) { for(int j=0; j<n; j++) { if(i+j==n-1) cout<<a[i][j]; else cout<<"\t"; } cout<<endl; } getch(); } Output