Question

The first issue: write a program in C #, which does the following: 1- Read two...

The first issue: write a program in C #, which does the following:
1- Read two string strings str1 and str2 entered by the user so that each one is composed
from at least five characters.
2- Transferring the first two letters of the str1 to the end of the str2, then writing each of them.
3- Delete the first and last characters of the str2 string, then write the new string that results from
Deletion process.
4- Moving two letters from the middle of the first series str1 to the middle of the second series str2 and writing each of them;
5- Prints the number of times the letter 'a' in both str1 and str

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

===========================================================================

using System;

class MainClass

{

public static void Main (string[] args)

{

Console.WriteLine("\nEnter any two strings with minimum 5 characters length:");

Console.Write("Enter string 1: ");

string str1 = Console.ReadLine();

Console.Write("Enter string 2: ");

string str2 = Console.ReadLine();

string str1dup;

string str2dup;

Console.WriteLine("\nAfter transferring the first two letters of the string 1 to the end of the string 2:");

str1dup = str1.Remove(0,2);

str2dup = str2.Insert(str2.Length,str1.Remove(2));

Console.WriteLine("String 1: " + str1dup);

Console.WriteLine("String 2: " + str2dup);

Console.WriteLine("\nAfter deleting the first and last characters of the string 2:");

str2dup = str2.Remove(str2.Length-1);

str2dup = str2dup.Remove(0,1);

Console.WriteLine("String 2: " + str2dup);

Console.WriteLine("\nAfter moving two letters from the middle of the first string to the middle of the second string:");

str1dup = str1.Remove(str1.Length/2,2);

str2dup = str2.Insert(str2.Length/2,str1.Substring(str1.Length/2,2));

Console.WriteLine("String 1: " + str1dup);

Console.WriteLine("String 2: " + str2dup);

char[] chars1 = str1.ToCharArray();

int count=0;

for(int i=0;i<str1.Length;i++)

if(chars1[i] == 'a')

count++;

char[] chars2 = str2.ToCharArray();

for(int i=0;i<str2.Length;i++)

if(chars2[i] == 'a')

count++;

Console.WriteLine("\nNo. of times the letter 'a' in both string 1 and string 2: " + count);

}

}

using System; class Mainclass public static void Main (string[] args) Console.WriteLine(\nEnter any two strings with minimum

Console.WriteLine(\nAfter moving two letters from the middle of the first string to the middle of the second string:); stri

======================================================================

Output:

Enter any two strings with minimum 5 characters length: Enter string 1: public Enter string 2: private After transferring the

===============================================================================

Hope it will usefull and do comments for any extra info if needed. Thankyou

===============================================================================

Add a comment
Know the answer?
Add Answer to:
The first issue: write a program in C #, which does the following: 1- Read two...
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
  • In C programming Write the implementation for the three functions described below. The functions are called...

    In C programming Write the implementation for the three functions described below. The functions are called from the provided main function. You may need to define additional “helper” functions to solve the problem efficiently. Write a print_string function that prints the characters in a string to screen on- by-one. Write a is_identical function that compares if two strings are identical. The functions is required to be case insensitive. Return 0 if the two strings are not identical and 1 if...

  • C programming Write the implementation for the three functions described below. The functions are called from...

    C programming Write the implementation for the three functions described below. The functions are called from the provided main function. You may need to define additional “helper” functions to solve the problem efficiently. a) Write a print_string function that prints the characters in a string to screen on- by-one. b) Write a is_identical function that compares if two strings are identical. The functions is required to be case insensitive. Return 0 if the two strings are not identical and 1...

  • From the Tony Gaddis text, the chapter on C-String and Class String: String Length: Write a...

    From the Tony Gaddis text, the chapter on C-String and Class String: String Length: Write a Function that passes in a C-String and using a pointer determine the number of chars in the string.                                           Data:   “This is a test string for string length” Prt String Backwards: Write a Function that passes in a C-String and prints the string backwards.      Data: “This is a test string for string backwards” replaceSubstring: Write a Function that accepts three C-Strings – str1,...

  • Write a program(Python language for the following three questions), with comments, to do the following:   ...

    Write a program(Python language for the following three questions), with comments, to do the following:    Ask the user to enter an alphabetic string and assign the input to a variable str1. Print str1. Check if str1 is valid, i.e. consists of only alphabetic characters. If str1 is valid Print “<str1> is a valid string.” If the first character of str1 is uppercase, print the entire string in uppercase, with a suitable message. If the first character of str1 is...

  • /* * CPS150_Lab10.java */ import java.io.*; import java.util.*; /** * CPS 150, Fall 2018 semester *...

    /* * CPS150_Lab10.java */ import java.io.*; import java.util.*; /** * CPS 150, Fall 2018 semester * * Section N1 * * Lab Project 13: Comparing Java Strings * * @author *** Replace with your name *** */ public class CPS150_Lab13 { static final Scanner KBD = new Scanner(System.in); static final PrintStream OUT = System.out; // TO DO: Implement each of the following 4 methods, // using the String compareTo method: /* * lessThan(String, String) -> boolean * * method is...

  • Can someone help me out with this? You are given a program that receives four lines...

    Can someone help me out with this? You are given a program that receives four lines in the below format, and stores them in str1, str2, str3, and num1. This is not a very long sentence. is long 4 Expand this program to: Write an if-elseif-else statement to print this line only if num1 is higher than 0: "Num1 is higher than 0!" print this line only if num1 is 0: "Num1 equals to 0!" And otherwise, print: ""Num1 is...

  • SCREENSHOTS ONLY PLEASE!!! DON'T POST ACTUAL CODE PLEASE LEAVE A SCREENSHOT ONLY! ACTUAL TEXT IS NOT NEEDED!!! myst...

    SCREENSHOTS ONLY PLEASE!!! DON'T POST ACTUAL CODE PLEASE LEAVE A SCREENSHOT ONLY! ACTUAL TEXT IS NOT NEEDED!!! mystring.h: //File: mystring1.h // ================ // Interface file for user-defined String class. #ifndef _MYSTRING_H #define _MYSTRING_H #include<iostream> #include <cstring> // for strlen(), etc. using namespace std; #define MAX_STR_LENGTH 200 class String { public: String(); String(const char s[]); // a conversion constructor void append(const String &str); // Relational operators bool operator ==(const String &str) const; bool operator !=(const String &str) const; bool operator >(const...

  • Note that the main function that I have provided does use <string.h> as it constructs test...

    Note that the main function that I have provided does use <string.h> as it constructs test strings to pass to your functions. However, your solutions for the 5 functions below may not use any of the built-in C string functions from the <string.h> library. Write a function called strcmp373. This function is passed two parameters, both of which are C strings. You should use array syntax when writing this function; that is, you may use [ ], but not *...

  • Write a C program that takes two sets of characters entered by the user and merge...

    Write a C program that takes two sets of characters entered by the user and merge them character by character. Enter the first set of characters: dfn h ate Enter the second set of characters: eedtecsl Output: defend the castle Your program should include the following function: void merge(char *s3, char *s1, char *s2); The function expects s3 to point to a string containing a string that combines s1 and s2 letter by letter. The first set might be longer...

  • Need help coding these two C programs 1:27 LTE < s3?bucket-uploads&prefix-attach%2Fjl CS 100 Exam Two -Coding...

    Need help coding these two C programs 1:27 LTE < s3?bucket-uploads&prefix-attach%2Fjl CS 100 Exam Two -Coding -Spring 2018 You are not allowed to use the Internet while coding the two problems below. You can log into the cs-intro server to test your programs if you wish When you have finished submit your exam via Blackboard Create a directory called exam2 using mkdir exan2 and move into that dinectory with ed exan2 Complete the I. Name this program one.c-This peogram reads...

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