c++ assignment
c++ assignment
Write a C++ program that counts the letters, spaces, numbers, and other characters in a string
you input
2. Write a C++ program that finds the largest word in a given string.
3. Write a C++ program that capitalizes the first letter of each word in a given string, where
words are separated by a single space
4. write a C ++ program to merge two sorted arrays into a single array
5. Write a C++ function to find the intersection of two array
6. Write a C ++ program to find kth smallest elements of an array
7. Create a C++ function to rearrange positive and negative numbers alternatively in an array.
8. Write a C++ program to find the sum of all elements in an integer array using pointers. The program
should take an array of integers as input and output the sum.
9. Write a C++ program to find the majority element (element that appears more than n/2 times)
in an array.
10. Write a C++ program that finds the largest element in an integer array using pointers. The
program should print the largest element and its position in the array.
11. Write a C++ program to search for an element in an array. The program should take an array
and a number as input and return the index of the element if it exists. If the element is not
found, return -1.
12. Write a C++ program that counts how many even and how many odd numbers are present in
an array of integers. The program should take an array as input and print the count of even
and odd numbers.
13. Write a C++ program to find the second largest element in a given array of integers. The
program should take an array as input and print the second largest element.
14. Write a C++ program to reverse an array using pointers. Take an array of integers as input, and
display the reversed array using pointer manipulation.
15. Write a program in C++ to find the sum of the digits of a given number by using function
16. Write a C++ program that demonstrates function overloading. Define two versions of a
function printSum():
One that takes two integers and prints their sum.
One that takes three integers and prints their sum.
17. Write a C++ program that defines a function swapValues(int &x, int &y) that swaps the values of two
integers using pass-by-reference. The program should display the values of the integers before and
after calling the function.
18. Write a C++ program that defines a function findMax(int arr[], int size) that returns a pointer to the
largest element in an array. The program should display the value of the largest element.
19. Write a C++ program that uses a pointer to store and access a structure Person with the
following fields:
name (string)
age (integer)
The program should demonstrate how to assign values to structure members via a pointer and
display the values.
20. Write a C++ program that defines a structure Employee with the following fields:
name (string)
age (integer)
salary (float)
The program should store details of multiple employees (array of structures) and sort them based
on their salary in descending order.
21. Write a C++ program to convert a binary number to a decimal number using class.
22. Write a C++ program that defines a class Employee with the following attributes:
name (string)
salary (float)
A static data member employeeCount (int) that keeps track of the number of employees.
A constructor to initialize the name and salary and increment the employeeCount.
A static member function getEmployeeCount() that returns the current count of
employees.
The program should create a few Employee objects and display the total number of employees
23. Write a C++ program that defines a class Account with the following attributes:
accountNumber (string)
balance (float)
The class should:
The program should create an Account object, deposit and withdraw some amount, and display
the balance after each operation.
24. Write a C++ program that defines a class Complex to represent complex numbers. The class
should have:
Two private data members real and imaginary to store the real and imaginary parts
of the complex number.
Overload the + operator to add two complex numbers.
Create two complex numbers, add them using the overloaded + operator, and display
the result as a complex number (in the form a + bi).
25. Write a C++ program that defines a class Point to represent a 2D point with x and y
coordinates. The class should:
Overload the << operator to display the point in the format (x, y).
Overload the >> operator to take input for the point coordinates.
Allow the user to input the coordinates of the point using the >> operator and display the
point using the << operator.
26. Write a C++ program that:
The program should open the file for writing, write the data, and close the file.
The program should open the file for reading, read the data line by line, and print each line to the
console.
The program should ask the user to input the data and append it to the file. If the file doesn't
exist, the program should create a new file.
The program should consider spaces between words as separators, and it should skip over any
special characters or punctuation.
30. Write a C++ program that defines a class called Student which has the following attributes:
Name (string)
Roll number (integer)
Marks (array of 5 integers)
Requirements:
Use pointers for dynamic memory allocation (for the marks array).
Implement file handling for reading and writing data
It should covers the following concepts Class, Array, Pointer, Operator Overloading, and File
Handling