Professional Documents
Culture Documents
Task 1:
Read 10 numbers in an array. Each number must be between 10 and 100. As each number is read, print it
only if it is not a duplicate of a number already entered.
ANSWER:
#include<iostream>
#include<string>
using namespace std;
void main(){
int arr[10];
for(int i = 0;i<10;i++){
cout<<"Enter "<<i<<" number : ";
cin>>arr[i];
if ( arr[i]<10 || arr[i]>100){
while(arr[i]<10 || arr[i]>100){
cout<<"Enter wrong value .... Enter "<<i<<" value again : ";
cin>>arr[i];
}
}
}
for (int i =0 ; i<10 ; i++){
for(int y=1;y<10;y++){
if (arr[i]== arr[y]){
arr[i]=0;
break;
}
else
arr[i] = arr[i];
}
if (arr[i]> 0)
cout<<arr[i]<<endl;
}
system("pause");
}
ANSWER:
#include<iostream>
#include<string>
using namespace std;
struct teacher{
int id;
string name;
string designation;
};
void main(){
teacher a,b;
a=input(b);
cout<<"ID : "<<a.id<<endl;
cout<<"Name : "<<a.name<<endl;
cout<<"Designation : "<<a.designation<<endl;
system("pause");
}
Task 3:
Create a struct teacher which has id, name, and designation as its members. Pass a parameter of type
teacher it to function by reference and assign value to it. Now print it in main.
ANSWER:
#include<iostream>
#include<string>
using namespace std;
struct teacher{
int id;
string name;
string designation;
};
void main(){
teacher a;
input(a);
cout<<"ID : "<<a.id<<endl;
cout<<"Name : "<<a.name<<endl;
cout<<"Designation : "<<a.designation<<endl;
system("pause");
}
Total 40 Signature
Note : Attempt all tasks and get them checked by your Lab Instructor.