0% found this document useful (0 votes)
29 views4 pages

c++ assignment

The document contains a list of 30 C++ programming tasks that cover various concepts such as string manipulation, array operations, function overloading, classes, file handling, and pointers. Each task specifies a particular problem to solve, such as counting characters in a string, finding the largest word, merging arrays, and implementing classes for complex numbers and students. The tasks are designed to enhance programming skills and understanding of C++ features.

Uploaded by

Efeson Uliso
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views4 pages

c++ assignment

The document contains a list of 30 C++ programming tasks that cover various concepts such as string manipulation, array operations, function overloading, classes, file handling, and pointers. Each task specifies a particular problem to solve, such as counting characters in a string, finding the largest word, merging arrays, and implementing classes for complex numbers and students. The tasks are designed to enhance programming skills and understanding of C++ features.

Uploaded by

Efeson Uliso
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

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.

The class should have:

 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:

 Have a constructor to initialize the accountNumber and balance.


 Provide a member function deposit(float amount) that increases the balance.
 Provide a member function withdraw(float amount) that decreases the balance.
 Use appropriate access modifiers (public and private) for data encapsulation.

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.

The program should:

 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.

The program should:

 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:

 Creates a text file output.txt.


 Writes your name, age, and a short bio to the file.

The program should open the file for writing, write the data, and close the file.

27. Write a C++ program that:

 Reads the contents of an existing text file input.txt.


 Displays the contents on the screen.

The program should open the file for reading, read the data line by line, and print each line to the
console.

28. Write a C++ program that:


 Opens an existing file student_data.txt.
 Appends the following information about a student:
o Name (string)
o Roll Number (integer)
o Marks (float)

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.

29. Write a C++ program that:

 Reads the contents of an existing text file textfile.txt.


 Counts and displays the total number of words in the 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)

The class should include:

 A constructor to initialize the student's name, roll number, and marks.


 A function to calculate the total marks.
 An overloaded << operator to print the student details.
 A function that writes student details (name, roll number, total marks) to a file named
"student.txt".
 A function that reads the student details from "student.txt" and displays them on the
screen.

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

You might also like