Question

Controlling complexity is the essence of computer programming. Write a program that uses the C++ string functionality to co

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Q6.

#include <iostream>

#include<string.h>

using namespace std;

// code to count the vowles

int main() {

    // phrase

string phrase = "Controlling complexity in essence of computer programming.";

    // use length function to get the length of the string

int len = phrase.length();

    // intitialize the variable count_vowel to store the count

int count_vowel = 0;

    // now loop through each character in the string and check if they are vowels or not

for(int i = 0; i < len; i++) {

        // if the character is vowels then add 1 to count_vowel

if (tolower(phrase[i]) == 'a' || tolower(phrase[i]) == 'e' || tolower(phrase[i]) == 'i' || tolower(phrase[i]) == 'o' || tolower(phrase[i]) == 'u') {

count_vowel += 1;

}

}

    // display the result

cout << "following phrase: " << phrase << endl;

cout << "has " << count_vowel << " vowels." << endl;

return 0;

}

Q7.

// function to output the result of xor of A and B

/// input is bool values A and B

// output is a bool A xor B

bool bool_xor(bool A, bool B) {

    // if the both inputs are same we return false

    if (A == B) {

        return false;

    }

    // else we return true

    return true;

}

Q8.

// function to swap the character in the array

// input are: a characyer array, int i and int j

// function outputs nothing

void swap_char(char a[], int i, int j) {

    // store the element at ith position in variable c

    char c = a[i];

    // now copy the jth element to ith position

    a[i] = a[j];

    // now assign c to jth position

    a[j] = c;

}

Q9.

// function to reverse the string using the swap char function

// inputs are char array and length of array

// output is nothing

void reverseString(char s[], int len) {

    // initialize j

    int j = len-1;

    

    // loop from start to middle of the string

    for(int i = 0; i < len / 2; i++) {

        // call function to swap the characters

        swap_char(s, i, j-i);

    }

}

Add a comment
Know the answer?
Add Answer to:
"Controlling complexity is the essence of computer programming." Write a program that uses the C++ string...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program that prompts the user to input a string. The program then uses the...

    Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. #include <iostream> #include <string> using namespace std; void removeVowels(string& str); bool isVowel(char ch);...

  • ‘C’ programming language question Write a MENU DRIVEN program to A) Count the number of vowels...

    ‘C’ programming language question Write a MENU DRIVEN program to A) Count the number of vowels in the string B) Count the number of consonants in the string C) Convert the string to uppercase D) Convert the string to lowercase E) Display the current string X) Exit the program The program should start with a user prompt to enter a string, and let them type it in. Then the menu would be displayed. User may enter option in small case...

  • C++ programming language Write a program that contains following function: A function that receives a string...

    C++ programming language Write a program that contains following function: A function that receives a string of character, the function returns the number of letter c's or C's in the string the function receives

  • C++ ONLY Write a function, int flip(string a[], int n); It reverses the order of the...

    C++ ONLY Write a function, int flip(string a[], int n); It reverses the order of the elements of the array and returns n. The variable n will be greater than or equal to zero. Example: string array[6] = { "a", "b", "", "c", "d", "e" }; int q = flip(array, 4); // returns 4 // array now contains: "c" "" "b" "a" "d" "e" Write a function, int flip(string a[], int n); It reverses the order of the elements of...

  • Write a C/C++ program that simulate a menu based binary number calculator. This calculate shall have the following three...

    Write a C/C++ program that simulate a menu based binary number calculator. This calculate shall have the following three functionalities: Covert a binary string to corresponding positive integers Convert a positive integer to its binary representation Add two binary numbers, both numbers are represented as a string of 0s and 1s To reduce student work load, a start file CSCIProjOneHandout.cpp is given. In this file, the structure of the program has been established. The students only need to implement the...

  • LANGUAGE = C i. Write a program that takes int numbers from user until user gives...

    LANGUAGE = C i. Write a program that takes int numbers from user until user gives a sentinel value (loop terminating condition). Sort the numbers in ascending order using Insertion sort method. Sorting part should be done in different function named insertionSort(). Your code should count the number of swaps required to sort the numbers. Print the sorted list and total number of swaps that was required to sort those numbers. (4 marks) ii. In this part take another number...

  • I was asked to write a program that when divisible by 2- reverses the order of...

    I was asked to write a program that when divisible by 2- reverses the order of the letters in a sentence when divisible by 3- changes all lowercase letter into uppercase letters in a sentence when divisible by 5 skips the vowels in a sentence this is what I have so far. my reverseMode works fine. #include <iostream> #include <string> #include<cstring> using namespace std; void reverseMode(char* str); void upperMode(char* str); void goodbyeVowels(char* str); char str[50], rstr[50]; //initializing my character arrray...

  • c++ #include <iostream> #include <string> using namespace std; /* Write a function checkPrime such that input:...

    c++ #include <iostream> #include <string> using namespace std; /* Write a function checkPrime such that input: an int output: boolean function: Return true if the number is a prime number and return false otherwise */ //TO DO ************************************** /* Write a function checkPrime such that input: an array of int and size of array output: nothing function: Display the prime numbers of the array */ //TO DO ************************************** /* Write a function SumofPrimes such that input: an int output: nothing...

  • Write a method called printReverse() that takes a string and uses recursion to print the contents...

    Write a method called printReverse() that takes a string and uses recursion to print the contents of the string in reverse order. The string itself should not be reversed; it must be left in its original form. The method has the following header:   void printReverse(String s, int i) where s is a reference to the string, and i is an integer parameter that you may use as you see fit. You do not need to code up this method as...

  • in c++ Program 1 Write a program that sorts a vector of names alphabetically using the...

    in c++ Program 1 Write a program that sorts a vector of names alphabetically using the selection sort and then searches the vector for a specific name using binary search. To do that, you need to write three functions I. void selSort (vector string &v: sorts the vector using selection sort 2. void display (const vector <string & v): displays the vector contents . int binSearch (const vector <ing& v, string key): searches the vector for a key returns the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT