Programming Fundamentals: Topic Objectiv e
Programming Fundamentals: Topic Objectiv e
Lab-7
Topic Functions
Objectiv Learning objectives of this lab is to understand how functions works.
e
Question 1: Use the readfile() function to read data from file “data.txt” into array. Make a
function check() that accepts the array and calculates the frequency of first even number
other than than 2 and calculates its sum. Display the number ,sum and frequency in main()
Sample Output:
Data.txt: 1 3 5 2 7 9 1 2 5 6 4 8 6 5 6
Output: First even number
found:6 Frequency is: 3
Sum is: 18
Question 2: Make a function readfile() that reads animal names from a file animal.txt into an
array[]. ask user to enter name of an animal into name[]. Make a function check() that
accepts array[] and animal that checks if animal entered by user is present in file or not.
Display the output on console.
Sample Output:
Animal.txt: ratcowelephanthorselion
Question 3: Write a C++ program that asks user to enter a word and store into word[]. Call a function
palindrome() that accepts word[] and checks if the word is palindrome or not. If the word is palindrome,
call a function changecase[] that accepts word[] and changes its case. If the word is not palindrome, call a
function reverse() that accepts word[] and update it in reverse order. Display the output in main().
Sample Output:
Enter a word: ISI
Word is palindrome: isi
1
Question 4: Write a C++ program to read a character array from file “input.txt” .Call a function
remove_vowels() and delete all the vowels from the character array and save it in new file “update.txt”.
Make as necessary functions you need to complete the task.
input.txt:
update.txt:
Question 5: Write a C++ program that reads a file name “full_name.txt” and write the abbreviations of
the first and middle names except the last name on the file “output.txt”. For example, if your name is
Robert Brett Roser, then the output should be R.B.Roser.Make as necessary functions you need to
complete the task.
fullname.txt:
R.B.Roser.
R.R Fenty.
K.E Hudson.