Assignment Y-1
Assignment Y-1
in c++
#include <iostream>
int main() {
int size;
matrix1[i][j] += matrix2[i][j];
return 0;
Q=2 Write a C++ program that takes a string from user and all remove characters from a string except alphabets.
#include <iostream>
string str;
getline(cin, str);
if (!isalpha(str[i])) {
str.erase(i, 1);
i--;
cout << "String after removing non-alphabets: " << str << endl;
return 0;
Q =3 Write a C++ function power () which takes two integers x and y as parameters and returns the value of x y. The
prototype of your function must be int power (int, int). Write appropriate main function to test the power function.
#include <iostream>
int main() {
int x, y;
cin >> x;
cin >> y;
cout << x << " raised to the power of " << y << " = " << result << endl;
return 0;
int result = 1;
for (int i = 0; i < y; i++) {
result *= x;
return result;
Q=4 Write a C++ function power () which takes addresses of two integers x and y as parameters.The prototype of your
function must be void power (int* x, int* y). Write appropriate main function to test the power function
#include <iostream>
int res = 1;
res *= *x;
cout << *x << " raised to the power of " << *y << " = " << res << endl;
int main() {
int x, y;
cin >> x;
cin >> y;
power(&x, &y);
return 0;
#include <iostream>
int main() {
int pos;
char * name;
int * one;
int * two;
int * three;
int result;
cout << "Enter your last name with exactly 10 characters." << endl;
cout << "If your name has <10 characters, repeat last letter." << "Blanks at the end do not count." << endl;
cout << "Enter three integer numbers separated by blanks" << endl;
cout << *one << " " << *two << " " << *three << endl;
cout << "The sum of the three values is " << result << endl;
delete one;
delete two;
delete three;
delete[] name;
return 0;
Q=6 Create a struct teacher which has employee id, name, and designation pass it to function by value and assign value to it
now print it in main. Pass it to function by reference and assign value to it and print it in main
#include <iostream>
int main() {
int result;
cout << "Numbers: " << *one << " " << *two << " " << *three << endl;
delete[] name;
delete one;
delete two;
delete three;
return 0;
Q=7 Create a struct student which has student id, name and cgpa as members. Create a static array of size 05 of type struct
student. Write a function Input_Record for taking record of 05 students. Write a function display to print contents of array on
output screen. C++
#include <iostream>
#include <string>
int id;
string name;
float cgpa;
};
cout << "Enter Student " << i + 1 << " details:" << endl;
cin.ignore();
getline(cin, students[i].name);
int main() {
Student students[5];
Input_Record(students);
Display(students);
return 0;
Q=9 Create a struct employee which has employee_id, name and name, age as members. Create a dynamic array of size 05
of type struct employee. Write a function Input_Record for taking record of 05 employees. Write a function display to print
contents of array on output screen.
#include <iostream>
#include <string>
int id;
string name;
int age;
};
cout << "Enter Employee " << i + 1 << " details:" << endl;
cin.ignore();
getline(cin, e[i].name);
int main() {
Input_Record(employees, size);
Display(employees, size);
delete[] employees;
return 0;}