Practice Question On Char Array
Practice Question On Char Array
Practice Question On Char Array
Naming convention: size means total capacity of array, length means actual numbers of element
present in array
Simple Questions
Q1. Create a character array of size 10 and initialize array with following 10 characters. In the end print
all characters on screen.
Q2. Create a char array of length 20 and initialize with phrase, “I am Batman” in the array. Then display
array with and without loop. Note: we are using double quotation method instead of braces to
initialize character array.
Q3. Create a character array of size 10. Ask user to enter 10 characters using loop and display them on
screen.
Q4. Create a character array of size 20 and ask user to enter a string without loop. Display string without
loop on screen.
Q5. Create an array of size 30 and ask user to enter string. Your program should find the length of array.
Q6. Create an array of size 30 and ask user to enter string. Your program should print array in reverse
order.
Q7. Initialize a character array of size 30.Your program should print all alphabets on screen (Capital and
small).
Q8. Create a character array of size 30. Ask user to enter a string, and your program should count total
number of characters, capital alphabets, small alphabets, integer character and special characters.
Q9. Initialize a character array of size 30.Your program should take a character from user and search it in
character array.
Q10. Initialize a character array of size 30.Your program should take a character from user and print
frequency of that character.
Q11. Initialize a character array of size 30.Your program should take a two character value and
replacement from user. After taking input replace all occurrences of character value with character
replacement.
Q12. Initialize a character array of size 30.Your program should take a two character value and
replacement from user. After taking input replace only last occurrences of character value with
character replacement.
Q13. Create a character array of size 30. Ask user to enter a string and your program should convert
capital alphabets to small and vice versa.
Complex Questions
Q1. Initialize a character array of size 30. Your program should rotate it left and right until user press $.
Press L for left shift and R for right shift.
Q2. Initialize a character array of size 30.Your program should find whether string is palindrome or not?
Q3.Demo file contain functions related to string manipulation. Run the code and see how each
Demo.cpp
function works and then create a program that mimic above functions in given
program. Write separate code for each function.
1 strcpy(s1, s2);
Copies string s2 into string s1.
2 strcat(s1, s2);
Concatenates string s2 onto the end of string s1.
3 strlen(s1);
Returns the length of string s1.
4 strcmp(s1, s2);
Returns 0 if s1 and s2 are the same; less than 0 if s1<s2; greater than 0 if s1>s2
Q4.The Pakistan studies teacher at your school needs help in grading a True/False test. Write a
program that asks a user to enter option either True (T), False (F) or space for each
question. As shown below
T F T T F T T F T
The answer to question 1 is true, the answer to question 2 is False, and student did not
answer question 4. The exam has 10 questions. Each correct answer is awarded two points,
each wrong answer gets one point deducted, and no answer gets zero points.
A. Write a program that calculates the total marks obtained by a student
B. Do the above program for ten students and find the Roll# of student whose marks are
highest.
Note: Roll# of first student is 1, second is 2 and so on
Q5. Write program that finds consecutive character pattern and print all pattern on screen.
Taaadhfffgabcdhyutew
aaa
fff
Q6. Initialize a string of size 40. Write a program that prints all unique alphabets from string. After
printing them sort them in ascending order.
For example: Hi world I am here to help you.
Unique characters are: H, I, W, O, R, L, D, A, M, E, T, P, Y, U.
Sorted: A, D, E, H, I , L,M, O, P, R, T, U, W, Y
Q3.
University of Central Punjab (UCP) is arranging a competition of programming, in which IT
department student can participate. In this competition student will be asked questions
(True/False) and student will be given points, in the end student whose points are higher will be
winner. Student whose marks are second highest is called runner up.
User will enter 3 options either True (T), False (F) or space for each question. As shown
below
T F T T F T T F T
The answer to question 1 is true, the answer to question 2 is False, and student did not
answer question 4. The exam has 10 questions.
Each correct answer is awarded two points, each wrong answer gets one point
deducted, and no answer gets zero points.
Assume there are 10 students so you have to ask 10 strings of True false as seen above.
Before entering answer ask user to write his/her serial number. So you have two array
one contain roll number and one contains marks of each student. This concept is called
parallel array. Note: please make sure using programming, that user should enter a
unique serial#, if it selects a previously available serial#, tell /her to enter again.
Generate a random key that have correct answers in order to give students marks.
Tasks to be done:
Q1. Print winner and runner up serial# along with marks
Q2.Print all participants serial # and marks in descending order(parallel sorting)
Q3.Print average of marks of all students