Practice Question On Char Array

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

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

Challenging and Application based Questions


Q1. Take a string and find the longest pattern within the array. A pattern for this challenge
will be defined as: if, at least, 2 or more adjacent characters within the string repeat itself at
least twice. For example "aabecaa" contains the pattern aa, on the other hand "abbbaac"
doesn't contain any pattern. Your program should print yes pattern or no Null. So, if a string
is "aabejiabkfabed", the output should be yes abe. If a string is "123224", the output should
return No null. If a char array, for example, is "aa2bbbaacbbb", the pattern is "bbb". You
must print the longest possible pattern. A string may either contain all characters (a through
z only), integers, or both. But the array will be of a character type. The maximum length for
the array will be 20 characters
Q2. Spam emails are always undesirable. Advance filtering system on email server help in
reducing the spam traffic. But on the other hand spammers are trying new ways to go
undetected. Spammers are using jumbled words, slightly wrong spellings, images and other
text crypto techniques. Spam Guard LLC is the leading developer of Spam Filters. They are
hiring new talent for developing Next Generation Spam filtering system. One major part of
the system is text analysis. Use the given text and perform the task given below to get
qualified for screening test: 
Text= “Permit me to inform you of my desire of going into business relationship with you. I
got your contact from the International web site directory. I prayed over it and selected
your name among other names due to esteeming nature and the recommendations given
to me as a reputable and trust worthy person I can do business with and by the
recommendations I must not hesitate to confide in you for this simple and sincere business.
I am Wumi talat; the only Daughter of late Mr and Mrs George tebet. My father was a very
wealthy cocoa merchant in Abidjan,the economic capital of Ivory Coast before he was
poisoned to death by his business associates on one of their outing to discuss on a business
deal. When my mother died on the 21st October 1984, my father took me and my younger
brother HASSAN special because we are motherless. Before the death of my father on 30th
June 20102 in a private hospital here in Abidjan. He secretly called me on his bedside and
told me that he has a sum of $12.500.000 Twelve Million, five hundred thousand dollars left
in a suspense account in a local Bank here in Abidjan, that he used my name as his first
Daughter for the next of kin in deposit of the fund. He also explained to me that it was
because of this wealth and some huge amount of money his business associates supposed
to balance his from the deal they had that he was poisoned by his business associates, that I
should seek for a God fearing foreign partner in a country of my choice where I will transfer
this money and use it for investment purpose, such as real estate management. Sir, we are
honorably seeking your assistance in the following ways.” 
 List all the words in the text (words may be ending with full stop, and there may be 2 or
more spaces in words)
 Find the words that starts from s or S
 Count the number of sentences (note: sentence is collection of words ends by full stop)

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. 

You are required to simulate this scenario using C++.

 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

Sample Output: (for 3 students)


Please enter your serial Number: 123
Please enter questions answers: F F T T T T T F T

Please enter your serial Number: 123


Sorry this serial number is already present! Enter again: 453

Please enter questions answers: T F F T T T T T F T


Please enter your serial Number: 143
Please enter questions answers: F T F T F F F F F T

Answers to questions are: F T F T T T T T F T

Winner student is: 123 with marks 18


Runner up is: 453 with marks 14

Marks of Students are:


123 18
453 14
143 8
Average of marks is: 13.333

You might also like