Question

In: Computer Science

How do I write a C# and a C++ code for creating a character array containing...

How do I write a C# and a C++ code for creating a character array containing the characters 'p', 'i', 'n','e','P','I','N','E' only and then using these lower and capital case letter character generate all possible combinations like PInE or PinE or PIne or PINE or piNE etc. and only in this order so if this order is created eg. NeIP or EnPi or NeIP or IPnE and on. You can generate all the combinations randomly by creating the word pine in any combination of lowercase or uppercase letters.Such that if the user entered PiNe or in this order, the compiler would recognize this order and print out the PiNe entered by the user.

Solutions

Expert Solution


#include <iostream>
#include<bits/stdc++.h> 
using namespace std;

// function to generate all possible combinations of given char array
void generate(char arr[],string res[],char temp[],int low,int high,int ind,int size) 
{ 
        if(ind==size) 
        { 
        string s="";
                for (int i=0;i<size;i++) 
                {
                    s+=temp[i];
                }
                int i=0;
        while(res[i]!=""){// move till empty location 
            i++;
        }
        res[i]=s;// store word formed in string array res
                return; 
        } 
        for(int i=low;i<=high&&high-i+1>=size-ind;i++) 
        { 
                temp[ind]=arr[i]; 
                generate(arr,res,temp,i+1,high,ind+1,size); 
        } 
} 

// driver code 
int main() 
{ 
        char array[] = {'p', 'i', 'n', 'e', 'P','I','N','E'}; // char array
        string res[5000]; 
        char temp[4];
        int n=sizeof(array)/sizeof(array[0]); 
        generate(array,res,temp,0,n-1,0,4);
        int i=0;
        cout<<"Enter word: ";
        string word;
        cin>>word;
        string w=word;
        transform(word.begin(),word.end(),word.begin(), ::tolower);// convert string to lower case
        while(res[i]!=""){
            if(res[i]==word){// word entered by used found in generated words
                cout<<w<<" entered by the user"<<endl;
                return 0;
            }
            i++;
        }
        cout<<"Cannot recongnized by compiler";// word not found
        return 0;
} 

//////////////C# code.........Another easy way is to convert entered word into lower case and then check if it equals to "pine"

using System;
class HelloWorld {
  static void Main() {
    char[] arr={'p','i','n','e','P','I','N','E'};
    string check="pine";
    string word;
    Console.Write("Enter word: ");
    word=Console.ReadLine();
    if(check.Equals(word.ToLower()))
        Console.Write("Entered by the user");
    else
        Console.Write("Cannot recongnized by the compiler");
  }
}

Related Solutions

c++ I need a code that will fill an array size of 1000, an array of...
c++ I need a code that will fill an array size of 1000, an array of size 2000, and an array size of 10000, with random int values. Basically like this: array1[1000] = filled all with random numbers array2[2000] = filled all with random numbers array3[10000] = filled all with random numbers C++ no need for print
Write a code using c# Maximum Sub Array.
Write a code using c# Maximum Sub Array.
Write a code in c++ using dynamic array of structure and dynamic array list. Make a...
Write a code in c++ using dynamic array of structure and dynamic array list. Make a dummy list for a company which stores following information about its customers. Customer ID Customer Name Gender Total items purchased Item category 20% discount in percentage of total purchase amount. Use dynamic array to save at least 20 items by dividing them into 3 different categories. Make a dummy list of items that company sells by dividing them into two categorizes. Items has following...
C++ Write the code to implement a complete binary heap using an array ( Not a...
C++ Write the code to implement a complete binary heap using an array ( Not a vector ). Code for Max heap. Implement: AddElement, GetMax, HeapSort, ShuffleUp, ShuffleDown, etc Set array size to 31 possible integers. Add 15 elements 1,3,27,22,18,4,11,26,42,19,6,2,15,16,13 Have a default constructor that initializes the array to zeros.. The data in the heap will be double datatype. PART 2 Convert to the program to a template, test with integers, double and char please provide screenshots thank you so...
Write MIPS assembly code for the following C code. for (i = 10; i < 30;...
Write MIPS assembly code for the following C code. for (i = 10; i < 30; i ++) { if ((ar[i] > b) || (ar[i] <= c)) ar[i] = 0; else ar[i] = a; }
I need the code for a C++ program that creates an array of 5000 String objects...
I need the code for a C++ program that creates an array of 5000 String objects that will store each word from a text file. The program will read in each word from a file, and store the first 5000 words in the array. The text file should be read in from the command line.
a) Write C code initialize an array of ints to the last four digits of your...
a) Write C code initialize an array of ints to the last four digits of your phone number. Use a loop to add the digits. Calculate and display the average of the digits. b) Write C code using a struct to hold student information: integer id integer number of hours taken integer number of hours passed double gpa
Write array methods that carry out the following tasks for an array of integers by creating...
Write array methods that carry out the following tasks for an array of integers by creating and completing the “ArrayMethods” class below. Add documentation comments for each method. Provide a test program called ‘Lab5_yourID.java” that test methods of ArrayMethods class. In your test program, use random class to generate array values. public class ArrayMethods { private int[ ] values; //declare instant variables public ArrayMethods (int[ ] initialValues) {values = initialValues;} //constructor public void shiftRight( ) { … } public Boolean...
What does the RISC-V code below do? Write the C equivalent. Assume that i is in...
What does the RISC-V code below do? Write the C equivalent. Assume that i is in register x5 and that the base address of array A that holds doubleword integers is in x20. addi x5, x0, 0 addi x6, x0, 50 addi x28, x20, 0 loop: bge x5, x6, end ld x7, 0(x28) bge x7, x0, next sub x7, x0, x7 sd x7, 0(x28) next: addi x5, x5, 1 addi x28, x28, 8 jal x0, loop end: Can you rewrite...
(In C language) Given a two-dimensional char array, how do I encode it into a one...
(In C language) Given a two-dimensional char array, how do I encode it into a one dimensional integer array? For example: char arr [8][8] = {{1,1,1,1,1,1,1,1}, {1,0,0,0,1,0,0,1}, {1,0,1,0,1,1,0,1}, {1,0,1,0,0,0,0,1}, {1,0,1,1,1,1,0,1}, {1,0,0,0,0,0,0,1}, {1,0,1,0,1,0,1,1}, {1,1,1,1,1,1,1,1}} into int arr2 [8] I know this problem requires bit-shifting but I am unsure how. It also needs to be as efficient as possible. Thanks!
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT