Question

Write a program in C++ that will take an input array e.g.; alphabet[] ={'A', 'B', 'C',...

Write a program in C++ that will take an input array e.g.; alphabet[] ={'A', 'B', 'C', 'D', 'E', 'F', 'G'}. print out every other character of the alphabet i.e.; A, C, E, G

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

Code:

//including iostream libraby for input and output to console

#include<iostream>

//we have to specify a namespace in c++

using namespace std;

//execution starts at main

int main(){

//defining a array for data type character to store alphabets

char alphabet[]={'A','B','C','D','E','F','G'};

//we can use a for loop to iterate through array(for loop is a default functionality in c++ to execute some statements repeatedly)

//calculating the size of array

int array_size=sizeof(alphabet)/sizeof(char);

//int i=0 is a initial statement and

//this i<array_size will make sure statements inside the for loop will execute only till i is less than array size

//value of i will increment by 2 for each iteration

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

//cout is used to print alphabets to console

cout<<alphabet[i]<<",";

}

}

OUTPUT:

A,C,E,G,

Code with out comments:

#include<iostream>

using namespace std;

int main(){

char alphabet[]={'A','B','C','D','E','F','G'};

int array_size=sizeof(alphabet)/sizeof(char);

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

cout<<alphabet[i]<<",";

}

}

Snapshot:

https:Whideword.sumantha repl.run clang version 7.0.0-3.ubuntu. 18.04.1 (tags/RELEASE_780/final) > clang++-7 -pthread -Std-c#

Add a comment
Know the answer?
Add Answer to:
Write a program in C++ that will take an input array e.g.; alphabet[] ={'A', 'B', 'C',...
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
  • CODE IN C++ 13.5 Alphabet Histogram Write a program that reads input character by character from...

    CODE IN C++ 13.5 Alphabet Histogram Write a program that reads input character by character from the given data file "data.txt" The program should be case insensitive and count the number of occurances of each character in the alphabet. It should print a histogram of the results as follows: A : B : C : * D : * E : * F : G : H : I : J : * K : L : M : N...

  • Write a program that deletes an element of a one-dimensional array of characters. The program should:...

    Write a program that deletes an element of a one-dimensional array of characters. The program should: Ask user to input the number of characters in the array the values of the array a character to be deleted Call a method to delete the character Print the resulting array or, if the character is not found, print “Value not found” The method called by the main program should: Pass the array and the character to be found as parameters If the...

  • Write a C program named space_to_line.c that features a while loop that continuously reads input from...

    Write a C program named space_to_line.c that features a while loop that continuously reads input from the user one character at a time and then prints that character out. The exception is that if the user inputs a space character (‘ ‘), then a newline character (‘\n’) should be printed instead. This will format the output such that every word the user inputs is on its own line. Other than changing the spaces to newlines, the output should exactly match...

  • Write a program for IJVM called scramble that takes lowercase text from input and prints the...

    Write a program for IJVM called scramble that takes lowercase text from input and prints the next character (i.e. ‘b’ is printed as ‘c’) and uppercase text and prints the character before (‘B’ is printed as ‘A’). Print all other characters as is.

  • Write Java code to implement a FSM machine that recognizes the language for the alphabet {a,b,c} ...

    Write Java code to implement a FSM machine that recognizes the language for the alphabet {a,b,c} consisting of all strings that contain two consecutive c's and end with b.                   Your FSM program should include the following three static methods (Java) or functions (C):                                           a.    int nextState(int state, char symbol)                                  A state-transition function that returns the next state based on the                                  current state and an input symbol. This function should also return                                  -1 when an invalid input character is detected.                                  State...

  • Create a program that takes in user input and stores the input into an array. Also...

    Create a program that takes in user input and stores the input into an array. Also within the program show how you can: show the elements in the array, remove an element from the array, add an element to the array. Do NOT ask the user how many elements they want to add, instead once they are done adding, they should hit ‘q’ and it should break out of the input. This is a c++ program. The input type shall...

  • C++ C++ Write a program to input eight integer numbers into an array named grade. As...

    C++ C++ Write a program to input eight integer numbers into an array named grade. As each number is input, add the number into a total. After all numbers are input, display the numbers and their average. (You can use cin to take number or use rand() to assign random numbers to the array.)

  • In C Programming Language, write a program Character Pointers and Functions. Keyboard input to enter one...

    In C Programming Language, write a program Character Pointers and Functions. Keyboard input to enter one character string. Using a single dimension array, populate the array with the character string, call a function using pointers to reverse order the character string, pass back to the main the output and total_count_of_characters. (maybe use a global variable for the total count). Print display the reversed char string and total_count.

  • In C Programming Language, write a program Character Pointers and Functions. Keyboard input to enter one...

    In C Programming Language, write a program Character Pointers and Functions. Keyboard input to enter one character string. Using a single dimension array, populate the array with the character string, call a function using pointers to reverse order the character string, pass back to the main the output and total_count_of_characters. (maybe use a global variable for the total count). Print display the reversed char string and total_count.

  • Write in C. Simple Program (beginner) Assignment: Write a program Character Pointers and Functions. (like program...

    Write in C. Simple Program (beginner) Assignment: Write a program Character Pointers and Functions. (like program #5-5). Keyboard input to enter one character string. Using a single dimension array, populate the array with the character string, call a function using pointers to reverse order the character string, pass back to the main the output and total_count_of_characters. (maybe use a global variable for the total count). Print display the reversed char string and total_count. <END>

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