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

write a program in C Write a function that is passed an array of characters containing...
write a program in C Write a function that is passed an array of characters containing letter grades of A, B, C, D, and F, and returns the total number of occurrences of each letter grade. Your function should accept both lower and upper case grades, for example, both 'b' and 'B' should be bucketed into your running total for B grades. Any grade that is invalid should be bucketed as a grade of 'I' for Incomplete. You must use...
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
C Write a function that appends the second character array to the first, replaces the first...
C Write a function that appends the second character array to the first, replaces the first array with the result and replaces the second character array with the original first array. For example, if the first character array is "hello" and the second is "world" at the end of the function the new value of the first character array should be"helloworld" and the second array should be "hello". If the input is invalid the function should return 1. Otherwise, the...
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...
i have an array of strings, how do i sort them into a binary tree? C...
i have an array of strings, how do i sort them into a binary tree? C Program
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 in C Language Write all these code in one program and upload. Consider this array...
Write in C Language Write all these code in one program and upload. Consider this array char address1 [ ] = "12330 Washington Blvd, suite 300, Sacramento, CA 94560-2341" ; (NOTE: The constant string on the RHS gets copied into the array address1 on the LHS) 1. Write a piece of code to count only letters in the string address1 using the function isAlpha   2. Convert to all Upper Case Write a program to convert address1 to all uppercase letters...
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT