Question

In: Computer Science

String Input Console Application and Program Analysis Demonstrate an understanding of basic C++ programming concepts by...

String Input Console Application and Program Analysis

Demonstrate an understanding of basic C++ programming concepts by completing the following:

  • Program: Create a simple C++ console application that will write a program that will take string input from a user. Your program should reverse the string and then print the output to the screen. Take input from the user 3 times for varying string lengths.
  • Program Analysis: Given your program implementation, discuss and identify the possible vulnerabilities that may exist. If present, discuss solutions to minimize the vulnerabilities. Then discuss and identify possible problems that can result in errors for string manipulation of data. Your program analysis should be 1-2 pages in length.

Solutions

Expert Solution

#include<iostream>

#include<string.h>

using namespace std;

int main(){

char str[100],temp;

cout<<"enter a string:";

gets(str);

int i=strlen(str)-1;

for(int j=0;j<i;j++,i--){

temp=str[j];

str[j]=str[i];

str[i]=temp;

}

cout<<"After reversing: "<<str;

return 0;

}

Program analysis:
This program takes an input of a string which can be of maximum size of 100.

The string length is calculated and is used further to reverse it

The for loop is responsible for reversing the string

The temporary variable 'temp' is used for swapping of the ith and the jth character of the string

The for loop will terminate when i is less than j.

The final result of str is printed.

User Inputs and Outputs:

1.

enter a string: AMMA

After reversing: AMMA

2.

enter a string: calculate

After reversing: etaluclac

3

enter a string: Abacus

After reversing: sucabA

Now we can conclude that the program works fine with given three variable length inputs.

Thus, the only care that needs to be taken is giving the input which is not null. The program doesn't crash. But the output would be null.

The length of the string or the size should also be taken care of while writing the program ad giving the input. Make sure to take the string size which suites the input that is to be given.

Make sure to import the libraries that are required for the functionality of the program. string.h in this case.

Also try to give good naming conventions when you are writing programs for better understanding.


Related Solutions

Integer Pointers Program and Analysis Demonstrate an understanding of basic C++ programming concepts by completing the...
Integer Pointers Program and Analysis Demonstrate an understanding of basic C++ programming concepts by completing the following: Program: Create a C++ program that asks the user to enter three integer values as input. Store the values into three different variables. For each variable, create three integer pointers that point to each value. Display the contents of the variables and pointers. In your program, be sure to use the new operator and delete operators to management memory. Program Analysis: Given your...
Write a basic C++ program with function, whose input is a character and a string, and...
Write a basic C++ program with function, whose input is a character and a string, and whose output indicates the number of times the character appears in the string. Ex: If the input is: n Monday the output is: 1 Ex: If the input is: z Today is Monday the output is: 0 Ex: If the input is: n It's a sunny day the output is: 2 Case matters. n is different than N. Ex: If the input is: n...
programming language is c#. Create a method that prompts a user of your console application to...
programming language is c#. Create a method that prompts a user of your console application to input the information for a student: static void GetStudentInfo() { Console.WriteLine("Enter the student's first name: "); string firstName = Console.ReadLine(); Console.WriteLine("Enter the student's last name"); string lastName = Console.ReadLine(); // Code to finish getting the rest of the student data ..... } static void PrintStudentDetails(string first, string last, string birthday) { Console.WriteLine("{0} {1} was born on: {2}", first, last, birthday); } 1. Using the...
a summary explaining the basic understanding of the following programming concepts using a language of python:...
a summary explaining the basic understanding of the following programming concepts using a language of python: •Variables •Arithmetic and Logical operations •Sequential coding (Structured programming •Decision structure (If statements) •Repetition structure •Functions with some coding demos inside visual studio code python IDE which can be sent as screenshot. preferably a typed summary please which can be written into powerpoint pleaseeeee ???
C# Programming Language Write a C# program ( Console or GUI ) that prompts the user...
C# Programming Language Write a C# program ( Console or GUI ) that prompts the user to enter the three examinations ( test 1, test 2, and test 3), homework, and final project grades then calculate and display the overall grade along with a message, using the selection structure (if/else). The message is based on the following criteria: “Excellent” if the overall grade is 90 or more. “Good” if the overall grade is between 80 and 90 ( not including...
In VB console write a Console Application that reads an input value for ??. You can...
In VB console write a Console Application that reads an input value for ??. You can assume that the user only inputs numeric values.
Write a C++ Program Write a program that prompts the user to input a string. The...
Write a C++ Program Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must insert the following comments at the beginning...
A C program that will perform the following: Input the string: Abc_3_deF Expected Output: The string...
A C program that will perform the following: Input the string: Abc_3_deF Expected Output: The string you entered is: aBC_Three_DEf An output for just this specific input will be fine. If you want to provide a program for all outputs, it would help with my understanding of how the program works overall as well but it is not needed. Thanks!
            It is not uncommon to develop the logic of a program as a console application...
            It is not uncommon to develop the logic of a program as a console application (NO GUI) and then graft a GUI on to it later. There are also many reasons for separating the GUI of the program from the rest of the code logic. (This is part of a common design pattern called Model View Controller (MVC) where the GUI represents the View aspect.) For instance, you might have a Web-based or mobile device GUI in addition to...
Using C# .NET Core console application that contains the following: 1. Use this variable: string baconIpsum...
Using C# .NET Core console application that contains the following: 1. Use this variable: string baconIpsum = "Bacon ipsum dolor amet picanha tri-tip pig pork bacon turducken. Leberkas short ribs prosciutto pork belly ribeye capicola alcatra short loin ham hock rump jowl pig flank beef. Venison tenderloin tail, cupim salami pastrami meatball jerky filet mignon. Salami jerky short loin, chicken pig pork tenderloin rump meatball sausage pancetta sirloin. Drumstick tenderloin ham pork belly cupim, ground round prosciutto jerky ball tip...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT