100% found this document useful (1 vote)
314 views

Programming Fundamentals: Topic Objectiv e

The document discusses functions and their usage through examples. It provides 5 questions to write C++ programs that utilize different functions to read data from files, perform operations on data, and write output to files. The questions cover functions for reading a file into an array, checking the array for a value, determining if a word is a palindrome, removing vowels from a character array, and writing abbreviated names to a file.

Uploaded by

prince12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
314 views

Programming Fundamentals: Topic Objectiv e

The document discusses functions and their usage through examples. It provides 5 questions to write C++ programs that utilize different functions to read data from files, perform operations on data, and write output to files. The questions cover functions for reading a file into an array, checking the array for a value, determining if a word is a palindrome, removing vowels from a character array, and writing abbreviated names to a file.

Uploaded by

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

Programming Fundamentals

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

Output: Enter the name of an animal:

horse Animal found

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().

Note: Call all functions from 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:

Heart made of glass and my mind of stone.

update.txt:

Hrt md f glss nd my mnd f stn.

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:

Robert Brett Roser


Robyn Rihanna
Fenty
Katheryn Elizabeth Hudson
output.txt:

R.B.Roser.

R.R Fenty.

K.E Hudson.

You might also like