Write a C++ program that reads a string and creates a cyclical array. A cyclical array is an array when the last element is pointing to the first one. Then write a loop that uses pointers and loops through the array starting from the first element and finishes after it visits the first element 5 times.
#include<iostream>
using namespace std;
class cyclic_array
{
public:
char c;
cyclic_array *next;
cyclic_array()
{
}
};
int main()
{
//reading a string
string s;
cout<<"Enter a string:";
cin>>s;
//creating cyclic array
cyclic_array *h=new cyclic_array();
cyclic_array *temp=h;
int i;
for(i=0;s[i]!=0;i++);
int l=i;
i=0;
while(i<l)
{
temp->c=s[i];
if(l-1!=i)
{
temp->next=
new cyclic_array();
temp=temp->next;
}
i++;
}
//linking to fist node
temp->next=h;
//printing 5 times
i=0;
temp=h;
while(i<5*l)
{
cout<<temp->c;
temp=temp->next;
i++;
}
cout<<endl;
return 0;
}
output:
Enter a string:hello
hellohellohellohellohello
Process exited normally.
Press any key to continue . . .
Write a C++ program that reads a string and creates a cyclical array. A cyclical array...
Write a Java program that does the following: 1. Creates a string array called firstNames that holds these values "John", "Frank", "Nick", "Amanda", "Brittany", "Amy", "Deborah", and "Stirling". 2. Creates another string array called lastNames that holds these values "Thompson", "Smith", "Jones", "Keribarian", "Lu", "Banafsheh", "Spielberg", "Jordan", "Castle" and "Simpson". 3. Now add a method that creates an array list called randomNames which picks a random first name from the array in step 1 and a random last name in...
C++. Write a program that copies the contents of one array into another array but in reverse order using pointers. - in main() - define 2 arrays of type int, 10 elements each - initialize one array with numbers 1 through 10 - initialize all elements of the second array to 0 - call function reverseCopy with both arrays as arguments - display the values of array number 2 (reversed order) - reverseCopy...
Please I need code in C++ Write a program that creates an int array of size 10, then uses a for-loop to populate the array with numbers from your favorite number pattern.
Please do it with C++. Thanks:) Write a program that reads a string and a character from the keyboard. The program should output how many times the character appears in the string. Make the program run in a loop until the string finish is input. Sample run: Input a string: alicia Input a letter: a The letter appears 2 times Input a string: felix Input a letter: x The letter appears 1 time Input a string: finish Good Bye.
Three C Code Questions: 5. Write a C program that declares an array of 10 strings, each of max length 50 characters, and then reads an entire line of text from the keyboard into each string. 6. Write C code that finds the longest name in this array of strings that you read in Q5. Hint: find the position of the longest string, not the string itself. 7. Write a C program that creates a 4 x 6 two dimensional...
Write a Java program in Eclipse. . Write a Java program that: 1. Creates an array of 100 integers. Initialize the array to have all zeros. 2. Puts even numbers starting from 6 (excluding multiples of 12) into the first 50 slots of the array above. So numbers 6,8,10,14,16,18,20,22,26, etc. go into the first 50 positions in the array. Print the array. 3. Puts random numbers between 45 and 55 into the second 50 slots of the array above (second...
Write a program in C that reads a string of bits( so either a one or zero) in from the user one char at a time using the function getChar, which returns a char. hint in order to convert a char to an int, subtract the character. Then store the bits into an array. start with this: #include "stdio.h" #define MAX_BITS 32 int main() { printf("Enter up to 32 bits (hit 'enter' to terminate early): "); char bit = getchar();...
Write a program that creates an array of 10 integers. The array should be populated with values: each element should be equal to its subscript/index. The program should then print each element. Make use of a loop in storing values to the array. Make use of another loop in printing the values of the array.
Write a Perl script that creates a string variable with value “This is String One”. Converts it into array, replaces value of element 2 from “String” to “Act” and transforms array back to string. Finally, it prints original string, array and transformed string.
This is binary search tree problem. The program reads the text file, and creates a binary search tree based on the words in the file. I can create the tree but I also have to store 'the order of insertion' in each node. For example, if text includes "the" 3 times and it is the 1st, 5th, and 9th word in the file, in binary search tree, one node should have string value "the" and array list{1, 5, 9}. How...