C / C++ Code Portfolio


return(EXIT_SUCCESS); // return success to calling function } // end function main Recursion



Download 112,15 Kb.
bet23/30
Sana01.03.2022
Hajmi112,15 Kb.
#475852
1   ...   19   20   21   22   23   24   25   26   ...   30
Bog'liq
dddd

return(EXIT_SUCCESS); // return success to calling function
} // end function main
Recursion
// This file contains two functions. Inline function isSeparator returns a bool if its input is a separator
// Function Reverse Recursively reads one character at a time from a text file until a separator is
// encountered as determined by function isSeparator. Those non-separator characters are then displayed in
// reverse order, with the last character displayed being capitalized.

#include


#include
#include
using namespace std;

inline bool isSeparator(int sepTest)
{
// if the input parameter sepTest is a separator as defined in the following list, return true
// otherwise, return false
return(isspace(sepTest) || (sepTest == '!') || (sepTest == ',') || (sepTest == ':') ||
(sepTest == ';') || (sepTest == EOF) || (sepTest == '.') || (sepTest == '?'));
}

int Reverse(ifstream &inFile, const int level)
{
// read in the next character from the file
int thisChar = inFile.get();
// if the character is a separator, return it to the caller
if (isSeparator(thisChar))
{
return(thisChar);
}
// if the character is not a separator...
else
{
// recursively recall this function, incrementing the recursion level
int thisSeparator = Reverse(inFile, level + 1);
// if the recursion level is one, it means we are ready to print the last character of the
// reversed word. It needs to be capitalized as well
if (level == 1)
{
cout << (char)toupper(thisChar);
}
// for any other recursion level, simply print the character
else
{
cout << (char)thisChar;
}
// return the result of the previous function call

Download 112,15 Kb.

Do'stlaringiz bilan baham:
1   ...   19   20   21   22   23   24   25   26   ...   30




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish