C++ OOP Practice Questions 2
-
Upload
zainzahid99 -
Category
Documents
-
view
215 -
download
0
Transcript of C++ OOP Practice Questions 2
-
8/18/2019 C++ OOP Practice Questions 2
1/7
2nd Week Worksheet
Objective : This Lab has been designed so that you should have a good grasp on the followingtopics after the completion of lab.1. Two dimensional Arrays
2. Sorting Arrays2.1 Bubble Sort2.2 Insertion Sort. Structure de!nition" Initiali#ation and usage$. AS%II &alues
Q.1. Write a program which can store a matrix data and display transpose
of matrix. ser sho!ld be able to enter matrix val!es at r!ntime and
display matrix data and its transpose. "reate a separate f!nction
#ranspose which accepts matrix as an arg!ment and displays its
transpose. $fter displaying transpose of matrix% program sho!ld give a
choice to !se whether to contin!e and repeat matrix inp!t or terminate.
#include
using namespace std;
void matrix(int arr[3][3])
{
int i,j;
cout
-
8/18/2019 C++ OOP Practice Questions 2
2/7
#
#
matrix(arr);
return !;
#
Q.2. Write a program to read 1& random integer val!es into an array.a' Write a !ser de(ned f!nction to sort the array !sing b!bble sort.b' Write a !ser de(ned f!nction to sort array !sing )elect sort*O#+: $rray will be passed to these f!nctions by reference from main
f!nction.
++
++ ame - &3.c%%
++ /utor - 0ain 0aid *1!2!!
++ ersion -
++ 4o%5rigt - 6our co%5rigt notice
++ 7escri%tion - 8ello 9orld in 4, /nsi:st5le++
#include
#include
#include
using namespace std;
void bubblesort(int arr[*!])
{
int i,j,tem%;
for(i!;i
-
8/18/2019 C++ OOP Practice Questions 2
3/7
mini;
if(arr[min]>arr[j])
minj;
if(mini)
{
tem%arr[i];
arr[i]arr[min];
arr[min]tem%;
#
#
#
for(i!;i
-
8/18/2019 C++ OOP Practice Questions 2
4/7
using namespace std;
struct student
{
char name[3!],classname[3!],section[3!],status;
int OtainedMarAs,$otalMarAs;
#;
int main() {
student s;
couts.name;
couts.classname;
couts.section;
couts.status;
couts.OtainedMarAs;
couts.$otalMarAs;
cout
-
8/18/2019 C++ OOP Practice Questions 2
5/7
++ 4o%5rigt - 6our co%5rigt notice
++ 7escri%tion - 8ello 9orld in 4, /nsi:st5le
++
#include
using namespace std;
struct student
{
char name[3!],classname[3!],section,grade;
int OtainedMarAs,$otalMarAs;
#;
int main() {
int i;
float total!.!;
student s[*!];
++$aAing Cn&ormation
for(i!;i
-
8/18/2019 C++ OOP Practice Questions 2
6/7
cout
-
8/18/2019 C++ OOP Practice Questions 2
7/7
if(ascii[j]>ascii[j*])
{
tem%ascii[j];
ascii[j]ascii[j*];
ascii[j*]tem%;
#
#
#
cout