Professional Documents
Culture Documents
20mid0209 - Lab 1
20mid0209 - Lab 1
LAB ASSIGNMENT – 1
1) Write a program to implement list and to perform operations:
Insertion and deletion, using array.
Program Code:
#include <iostream>
using namespace std;
class List {
private:
int arr[MAX_SIZE]; // Array to store the list elements
int size; // Current size of the list
public:
List() {
size = 0; // Initialize the list size to 0
}
int main() {
List myList;
return 0;
}
Screenshot:
Sample output:
2) Write a program using arrays
• To create a list L containing your date of birth in the following format:
ddmmyyyy
• To create a list M containing your pincode
• To merge the lists L and M ( L||M - || indicates concatenation)
• To split the list created in 3 into two equal parts
• To delete 0’s in the list L (created in 1)
• To duplicate odd numbers in the list M (created in 2) Eg, If the
pincode is 632178, then we o/p is 633211778
Program Code:
#include <iostream>
#include <vector>
using namespace std;
int dob[8];
int pin[6];
int merg[14];
return updatedL;
}
return updatedM;
}
int main() {
cout << "Enter your date of birth in format ddmmyyyy \n";
for (int i = 0; i < 8; i++) {
cin >> dob[i];
}
int j = 0;
int k = 0;
for (int i = 0; i < 8; i++) {
merg[i] = dob[j];
j++;
}
return 0;
}
Screenshot:
Sample Output:
Program Code:
#include <iostream>
#include <string>
int main() {
int n;
return 0;
}
Screenshot:
Sample Output:
4) Write a program to illustrate implementation of union.
Program Code:
#include <iostream>
#include <string.h>
int main()
{
union student // union is keyword & student is union name
{
char name[25];
int age;
float height;
}s; //instance s is created while declartion of union.
//instance can also be created after declaration as: union student s; or as: student
s;
strcpy( s.name, "sharan");
cout<<s.name<<endl;
s.age=21;
cout<<s.age<<endl;
s.height=181;
cout<<s.height<<endl;
return 0;
}
Screenshot:
Sample Output;
#include <iostream>
#include <string.h>
int main()
{
union student
{
char name[25];
int age;
float height;
}s;
strcpy( s.name, "sharan");
cout<<s.name<<endl;
s.age=21;
cout<<s.age<<endl;
s.height=181;
cout<<s.height<<endl;
cout<<"size of union s is "<<sizeof(s);
struct stud
{
char name[25];
int age;
float height;
}t;
return 0;
}
Screenshot:
Sample Output: