1, Write A progr-WPS Office
1, Write A progr-WPS Office
take two integers and perform different arithmetic operations (addition, subtraction)
#include <iostream>
int main() {
int choice;
// User input
if (choice == 1) {
} else if (choice == 2) {
} else {
return 0;
// Function definitions
return a + b;
}
return a - b;
2 Define a structure Node for a binary tree and write a recursive function to calculate the
#include <iostream>
struct Node {
};
return -1;
// The height of the tree is the maximum height of its subtrees plus one for the root
// Helper function to insert nodes into the binary tree (for testing)
if (root == nullptr) {
} else {
return root;
}
int main() {
insert(root, 5);
insert(root, 15);
insert(root, 3);
insert(root, 7);
insert(root, 12);
insert(root, 18);
std::cout << "The height of the binary tree is: " << treeHeight << std::endl;
return 0;
3 Define a structure Movie with title, director, and year as members. Allocate memory
dynamically for each movie’s title and director. Implement functions to add new movies
and display all movie details.
#include <iostream>
struct Movie {
~Movie() {
};
// Function to add a new movie
char title[100];
char director[100];
int year;
int main() {
int choice;
do {
switch (choice) {
case 1:
break;
case 2:
break;
case 3:
std::cout << "Exiting program.\n";
break;
default:
return 0;
4 Create an array of Person structures and implement a function to find the oldest person
#include <iostream>
struct Person {
};
Person oldest = people[0]; // Assume the first person is the oldest initially
for (int i = 1; i < size; ++i) {
int main() {
std::cout << "Enter name of person " << (i + 1) << ": ";
std::cout << "Enter age of person " << (i + 1) << ": ";
std::cout << "Name: " << oldest.name << ", Age: " << oldest.age << std::endl;
return 0;
5 Write a program that appends new student data (name and grade) to an existing file
#include <iostream>
#include <fstream>
#include <string>
int main() {
outFile.open(filename, std::ios::app);
if (!outFile) {
}
std::string name;
float grade;
outFile.close();