SlideShare a Scribd company logo
1 of 5
Download to read offline
#include #include // Read before you start: // Do not modify any part of this program that you
are given. Doing so may cause you to fail automated test cases. // You are given a partially
complete program. Your job is to complete the functions in order for this program to work
successfully. // You should complete this homework assignment using Microsoft Visual Studios
2013 (or a later version). // All instructions are given above the required functions, please read
them and follow them carefully. // If you modify the function return types or parameters, you
will fail the automated test cases. // You can assume that all inputs are valid. Ex: If prompted for
a char, the input will be a char. // Global Macro Values #define NUM_STRINGS 5 #define
STRING_LENGTH 32 // Forward Declarations void
frequency(char[NUM_STRINGS][STRING_LENGTH],char); void
remove_Number(char[NUM_STRINGS][STRING_LENGTH]); void
swapStrings(char[STRING_LENGTH], char[STRING_LENGTH]); void
sortStrings(char[NUM_STRINGS][STRING_LENGTH]); void
printStrings(char[NUM_STRINGS][STRING_LENGTH]); int
alpha_Counter(char[STRING_LENGTH]); int isAPalindrome(char[STRING_LENGTH]); void
addLetter(char[STRING_LENGTH], char, int); // Problem 1: frequency (5 points) // Rewrite
this function to perform the same task as in hw03, using only pointer operations. // You must use
pointer operations only. If you use array operations, you will recieve no credit for this part. //
You may use the code you submitted for hw03 or you may use the solution code for hw03. //
Traverse the 2D array of characters variable 'strings' and check the frequency of a particular
letter or a search_alphabetin a string. // In order to check the frequency, first you need to read the
search_alphabet from the user. // If the string is "hello" and the search_alphabet is l, the code
will count the number of 'l's in hello. // The output of the function for the above mentioned case
will be 2. //append that frequency value at the end of the string //for hello the new string will be
hello2 void frequency(char strings[NUM_STRINGS][STRING_LENGTH],char
search_alphabet) { } // Problem 2: remove_vowel (5 points) // Rewrite this function to
perform the same task as in hw03, using only pointer operations. // You must use pointer
operations only. If you use array operations, you will recieve no credit for this part. // You may
use the code you submitted for hw03 or you may use the solution code for hw03. //Traverse the
2D array of characters variable 'strings' and remove all vowels from the string. // In order to
remove all vowel characters, you need to check each letter of the string and decide whether its is
a vowel. If so then remove it. If not then check the next character. // If the string is "hello", your
result will be hll. //print the new string without vowel using problem 6. void remove_vowel(char
strings[NUM_STRINGS][STRING_LENGTH]) { } void swapStrings(char
string1[STRING_LENGTH], char string2[STRING_LENGTH]) { char
temp[STRING_LENGTH]; strcpy(temp, string1); strcpy(string1, string2);
strcpy(string2, temp); } // Problem 3: sortStrings (10 points) // Rewrite this function to perform
the same task as in hw03, using only pointer operations. // You must use pointer operations only.
If you use array operations, you will recieve no credit for this part. // You can use the
swapStrings() function if you'd like, but are not required to do so. // You may use the code you
submitted for hw03 or you may use the solution code for hw03. // // Sort the 5 strings contained
in the 2D character array parameter labeled "strings". // Sort the strings based on their ASCII
character value (use strcmp to compare strings). // See the output provided in the word document
for example input and output. void sortStrings(char
strings[NUM_STRINGS][STRING_LENGTH]) { } void printStrings(char
strings[NUM_STRINGS][STRING_LENGTH]) { int i; for (i = 0; i <
NUM_STRINGS; i++) { printf("%s ", strings[i]); } } // Problem 4:
vowelCounter (10 points) // This function accepts an array of characters and returns the number
of alphabets in that string (an integer). // You must use pointer operations only. If you use array
operations, you will recieve no credit for this part. // you should not count any number or special
character within the string int alpha_Counter(char string[STRING_LENGTH]) { } //
Problem 5: isAPalindrome (10 points) // This function accepts an array of characters and returns
an integer. // You must use pointer operations only. If you use array operations, you will recieve
no credit for this part. // This function should return 1 (true) if the parameter 'string' is a
palindrome, or 0 (false) if 'string' is not a palindrome. // A palindrome is a sequence of
characters which when reversed, is the same sequence of characters. // For this assignment, you
can assume that 'string' will be a single word containing only lowercase letters and no spaces. //
Example Palindromes: mom, racecar, stats, rotator, deleveled int isAPalindrome(char
string[STRING_LENGTH]) { } // Problem 6: addLetter (10 points) // This function
accepts an array of characters as well as a character to be added to the existig string and a
position where this new letter is to be added. // You must use pointer operations only. If you use
array operations, you will recieve no credit for this part. // All occurances of the
'letterToBeRemoved' should be removed from character array 'string' // Example: If string =
"letter", and letterToAdd = 'a'; the pos=2 after this function terminates, string should contain
"leatter" void addLetter(char string[STRING_LENGTH], char letterToAdd, int pos) { }
// You should study and understand how this main function works. // Do not modify it in any
way, there is no implementation needed here. void main() { int selection,i; char
input[STRING_LENGTH]; printf("Assignment 4: Pointer Operations  ");
printf("Choose one of the following:  1. Sorting Strings 2. Alphabet counter 3. Palindrome 4.
Letter Addition  "); scanf("%d", &selection); // store integer getchar(); // consume
newline char if (selection == 1) { char
strings[NUM_STRINGS][STRING_LENGTH]; // will store 5 strings each with a max length of
32 char search_alphabet; for (i = 0; i < NUM_STRINGS; i++) {
printf(" Enter the next String: "); // prompt for string fgets(input,
sizeof(input), stdin); // store input string input[strlen(input) - 1] = '0'; // convert
trailing ' ' char to '0' (null terminator) strcpy(strings[i], input); // copy input to
2D strings array } printf("Enter a character for checking its frequency:
"); // prompt for integer scanf("%c", &search_alphabet); // store integer
frequency(strings, search_alphabet); remove_vowel(strings); printf(" The strings
after vowel removal: "); printStrings(strings); sortStrings(strings);
printf(" Sorted Strings: "); printStrings(strings); } else if (selection == 2)
{ printf(" Enter a String: "); // prompt for string fgets(input,
sizeof(input), stdin); // store input string input[strlen(input) - 1] = '0'; // convert
trailing ' ' char to '0' (null terminator) int numAlpha = alpha_Counter(input);
printf(" There are %d alphabets in "%s"", numAlpha, input); } else if
(selection == 3) { printf(" Enter a String: "); // prompt for string
fgets(input, sizeof(input), stdin); // store input string input[strlen(input) - 1] = '0'; //
convert trailing ' ' char to '0' (null terminator) int isPalindrome =
isAPalindrome(input); if (isPalindrome) printf(" The string "%s"
is a palindrome", input); else printf(" The string "%s" is not a
palindrome", input); } else if (selection == 4) { printf(" Enter a String:
"); // prompt for string fgets(input, sizeof(input), stdin); // store input string
input[strlen(input) - 1] = '0'; // convert trailing ' ' char to '0' (null terminator)
char letterToAdd; int pos; printf(" Enter a letter to be added: "); // prompt
for char scanf(" %c", &letterToAdd); // store input char printf(" Enter the
array position for adding the letter:"); scanf("%d",&pos); addLetter(input,
letterToAdd, pos); printf(" Result: %s", input); } else {
printf("Program terminating..."); } }
Solution
PROGRAM CODE:
/*
* stringManipulation.cpp
*
* Created on: 11-Feb-2017
* Author: kasturi
*/
#include
#include
#include
// Read before you start:
// Do not modify any part of this program that you are given. Doing so may cause you to fail
automated test cases.
// You are given a partially complete program. Your job is to complete the functions in order for
this program to work successfully.
// You should complete this homework assignment using Microsoft Visual Studios 2013 (or a
later version).
// All instructions are given above the required functions, please read them and follow them
carefully.
// If you modify the function return types or parameters, you will fail the automated test cases.
// You can assume that all inputs are valid. Ex: If prompted for a char, the input will be a char.
// Global Macro Values
#define NUM_STRINGS 5
#define STRING_LENGTH 32
// Forward Declarations
void frequency(char[NUM_STRINGS][STRING_LENGTH],char);
//void remove_Number(char[NUM_STRINGS][STRING_LENGTH]);
void swapStrings(char[STRING_LENGTH], char[STRING_LENGTH]);
void sortStrings(char[NUM_STRINGS][STRING_LENGTH]);
void printStrings(char[NUM_STRINGS][STRING_LENGTH]);
int alpha_Counter(char[STRING_LENGTH]);
int isAPalindrome(char[STRING_LENGTH]);
void addLetter(char[STRING_LENGTH], char, int);
// Problem 1: frequency (5 points)
// Rewrite this function to perform the same task as in hw03, using only pointer operations.
// You must use pointer operations only. If you use array operations, you will recieve no credit
for this part.
// You may use the code you submitted for hw03 or you may use the solution code for hw03.
// Traverse the 2D array of characters variable 'strings' and check the frequency of a particular
letter or a search_alphabetin a string.
// In order to check the frequency, first you need to read the search_alphabet from the user.
// If the string is "hello" and the search_alphabet is l, the code will count the number of 'l's in
hello.
// The output of the function for the above mentioned case will be 2.
//append that frequency value at the end of the string
//for hello the new string will be hello2
void frequency(char strings[NUM_STRINGS][STRING_LENGTH],char search_alphabet)
{
char *tobeModified = &strings[0][0];
int i=0;
while(i 0)
swapStrings(temp1, temp2);
}
temp1 += STRING_LENGTH;
}
}
void printStrings(char strings[NUM_STRINGS][STRING_LENGTH])
{
int i;
for (i = 0; i < NUM_STRINGS; i++)
{
printf("%s ", strings[i]);
}
}
// Problem 4: vowelCounter (10 points)
// This function accepts an array of characters and returns the number of alphabets in that string
(an integer).
// You must use pointer operations only. If you use array operations, you will recieve no credit
for this part.
// you should not count any number or special character within the string
int alpha_Counter(char string[STRING_LENGTH])
{
int counter = 0, i=0;
char *pointer = &string[0];
while(i

More Related Content

Similar to #include stdio.h #include string.h Read before you start .pdf

Les origines de Javascript
Les origines de JavascriptLes origines de Javascript
Les origines de JavascriptBernard Loire
 
READ BEFORE YOU START You are given a partially completed pr.pdf
READ BEFORE YOU START  You are given a partially completed pr.pdfREAD BEFORE YOU START  You are given a partially completed pr.pdf
READ BEFORE YOU START You are given a partially completed pr.pdfarkurkuri
 
VTU DSA Lab Manual
VTU DSA Lab ManualVTU DSA Lab Manual
VTU DSA Lab ManualAkhilaaReddy
 
Error correction-and-type-of-error-in-c
Error correction-and-type-of-error-in-cError correction-and-type-of-error-in-c
Error correction-and-type-of-error-in-cMd Nazmul Hossain Mir
 
import java.util.Scanner;Henry Cutler ID 1234 7202.docx
import java.util.Scanner;Henry Cutler ID 1234  7202.docximport java.util.Scanner;Henry Cutler ID 1234  7202.docx
import java.util.Scanner;Henry Cutler ID 1234 7202.docxwilcockiris
 
Assignment c programming
Assignment c programmingAssignment c programming
Assignment c programmingIcaii Infotech
 
Functions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrupFunctions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrupSyedHaroonShah4
 
The concept of stack is extremely important in computer science and .pdf
The concept of stack is extremely important in computer science and .pdfThe concept of stack is extremely important in computer science and .pdf
The concept of stack is extremely important in computer science and .pdfarihantsherwani
 
Hacking parse.y (RubyKansai38)
Hacking parse.y (RubyKansai38)Hacking parse.y (RubyKansai38)
Hacking parse.y (RubyKansai38)ujihisa
 
C programming day#2.
C programming day#2.C programming day#2.
C programming day#2.Mohamed Fawzy
 
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 FocJAYA
 
C++ Programming Homework Help
C++ Programming Homework HelpC++ Programming Homework Help
C++ Programming Homework HelpC++ Homework Help
 
Please code in C language- Please do part 1 and 2- Do not recycle answ.docx
Please code in C language- Please do part 1 and 2- Do not recycle answ.docxPlease code in C language- Please do part 1 and 2- Do not recycle answ.docx
Please code in C language- Please do part 1 and 2- Do not recycle answ.docxcgraciela1
 
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docxAssignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docxbraycarissa250
 

Similar to #include stdio.h #include string.h Read before you start .pdf (20)

Javascript
JavascriptJavascript
Javascript
 
Les origines de Javascript
Les origines de JavascriptLes origines de Javascript
Les origines de Javascript
 
READ BEFORE YOU START You are given a partially completed pr.pdf
READ BEFORE YOU START  You are given a partially completed pr.pdfREAD BEFORE YOU START  You are given a partially completed pr.pdf
READ BEFORE YOU START You are given a partially completed pr.pdf
 
VTU DSA Lab Manual
VTU DSA Lab ManualVTU DSA Lab Manual
VTU DSA Lab Manual
 
Error correction-and-type-of-error-in-c
Error correction-and-type-of-error-in-cError correction-and-type-of-error-in-c
Error correction-and-type-of-error-in-c
 
import java.util.Scanner;Henry Cutler ID 1234 7202.docx
import java.util.Scanner;Henry Cutler ID 1234  7202.docximport java.util.Scanner;Henry Cutler ID 1234  7202.docx
import java.util.Scanner;Henry Cutler ID 1234 7202.docx
 
Ch09
Ch09Ch09
Ch09
 
Java 5 Features
Java 5 FeaturesJava 5 Features
Java 5 Features
 
Assignment c programming
Assignment c programmingAssignment c programming
Assignment c programming
 
Operator overloading
Operator overloading Operator overloading
Operator overloading
 
Functions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrupFunctions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrup
 
The concept of stack is extremely important in computer science and .pdf
The concept of stack is extremely important in computer science and .pdfThe concept of stack is extremely important in computer science and .pdf
The concept of stack is extremely important in computer science and .pdf
 
Hacking parse.y (RubyKansai38)
Hacking parse.y (RubyKansai38)Hacking parse.y (RubyKansai38)
Hacking parse.y (RubyKansai38)
 
C programming day#2.
C programming day#2.C programming day#2.
C programming day#2.
 
[ITP - Lecture 17] Strings in C/C++
[ITP - Lecture 17] Strings in C/C++[ITP - Lecture 17] Strings in C/C++
[ITP - Lecture 17] Strings in C/C++
 
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 Foc
 
C q 3
C q 3C q 3
C q 3
 
C++ Programming Homework Help
C++ Programming Homework HelpC++ Programming Homework Help
C++ Programming Homework Help
 
Please code in C language- Please do part 1 and 2- Do not recycle answ.docx
Please code in C language- Please do part 1 and 2- Do not recycle answ.docxPlease code in C language- Please do part 1 and 2- Do not recycle answ.docx
Please code in C language- Please do part 1 and 2- Do not recycle answ.docx
 
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docxAssignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
 

More from fckindswear

Nessus is a network security toolIn a pragraph describe how it is .pdf
Nessus is a network security toolIn a pragraph describe how it is .pdfNessus is a network security toolIn a pragraph describe how it is .pdf
Nessus is a network security toolIn a pragraph describe how it is .pdffckindswear
 
Luthans and Doh (2012) discuss two major forms of communication flow.pdf
Luthans and Doh (2012) discuss two major forms of communication flow.pdfLuthans and Doh (2012) discuss two major forms of communication flow.pdf
Luthans and Doh (2012) discuss two major forms of communication flow.pdffckindswear
 
Is the value of the Manufacturing Plant considered a long term or a .pdf
Is the value of the Manufacturing Plant considered a long term or a .pdfIs the value of the Manufacturing Plant considered a long term or a .pdf
Is the value of the Manufacturing Plant considered a long term or a .pdffckindswear
 
Indicate whether you agree or disagree with the following statements.pdf
Indicate whether you agree or disagree with the following statements.pdfIndicate whether you agree or disagree with the following statements.pdf
Indicate whether you agree or disagree with the following statements.pdffckindswear
 
Identify any relative maxima or minima and intervals on which the fun.pdf
Identify any relative maxima or minima and intervals on which the fun.pdfIdentify any relative maxima or minima and intervals on which the fun.pdf
Identify any relative maxima or minima and intervals on which the fun.pdffckindswear
 
How exposure to an argument through mass media may have influenced o.pdf
How exposure to an argument through mass media may have influenced o.pdfHow exposure to an argument through mass media may have influenced o.pdf
How exposure to an argument through mass media may have influenced o.pdffckindswear
 
Here is the company database--comments can be addedD.pdf
Here is the company database--comments can be addedD.pdfHere is the company database--comments can be addedD.pdf
Here is the company database--comments can be addedD.pdffckindswear
 
Find the IPv6 prefix of the address 20010fc3ca540 a0 10 if the .pdf
Find the IPv6 prefix of the address 20010fc3ca540 a0 10 if the .pdfFind the IPv6 prefix of the address 20010fc3ca540 a0 10 if the .pdf
Find the IPv6 prefix of the address 20010fc3ca540 a0 10 if the .pdffckindswear
 
Explain the kinds of information that must be maintained in fixed as.pdf
Explain the kinds of information that must be maintained in fixed as.pdfExplain the kinds of information that must be maintained in fixed as.pdf
Explain the kinds of information that must be maintained in fixed as.pdffckindswear
 
Dr. P has a culture of stem cells and she wants them to specialize i.pdf
Dr. P has a culture of stem cells and she wants them to specialize i.pdfDr. P has a culture of stem cells and she wants them to specialize i.pdf
Dr. P has a culture of stem cells and she wants them to specialize i.pdffckindswear
 
Describe two ecological roles of fungi. Related concepts decomposer.pdf
Describe two ecological roles of fungi. Related concepts decomposer.pdfDescribe two ecological roles of fungi. Related concepts decomposer.pdf
Describe two ecological roles of fungi. Related concepts decomposer.pdffckindswear
 
Differential equations using phase plane analysis. Task 1 (Romeo .pdf
Differential equations using phase plane analysis. Task 1 (Romeo .pdfDifferential equations using phase plane analysis. Task 1 (Romeo .pdf
Differential equations using phase plane analysis. Task 1 (Romeo .pdffckindswear
 
Develop a stack in c with dynamic memory allocation. Use the followi.pdf
Develop a stack in c with dynamic memory allocation. Use the followi.pdfDevelop a stack in c with dynamic memory allocation. Use the followi.pdf
Develop a stack in c with dynamic memory allocation. Use the followi.pdffckindswear
 
Define a struct type that represents a smartphone. The struct should.pdf
Define a struct type that represents a smartphone. The struct should.pdfDefine a struct type that represents a smartphone. The struct should.pdf
Define a struct type that represents a smartphone. The struct should.pdffckindswear
 
Changes in the economy have determined that for the EZ shipping comp.pdf
Changes in the economy have determined that for the EZ shipping comp.pdfChanges in the economy have determined that for the EZ shipping comp.pdf
Changes in the economy have determined that for the EZ shipping comp.pdffckindswear
 
Broadly speaking, the economy consists of households, firms, governm.pdf
Broadly speaking, the economy consists of households, firms, governm.pdfBroadly speaking, the economy consists of households, firms, governm.pdf
Broadly speaking, the economy consists of households, firms, governm.pdffckindswear
 
A committee consists of 13 Republicans and 16 Democrats. How many dif.pdf
A committee consists of 13 Republicans and 16 Democrats. How many dif.pdfA committee consists of 13 Republicans and 16 Democrats. How many dif.pdf
A committee consists of 13 Republicans and 16 Democrats. How many dif.pdffckindswear
 
2. July 01 Record the dividend received from the foreign subsidiary..pdf
2. July 01 Record the dividend received from the foreign subsidiary..pdf2. July 01 Record the dividend received from the foreign subsidiary..pdf
2. July 01 Record the dividend received from the foreign subsidiary..pdffckindswear
 
You have isolated a new virus, determined it has a lipid envelope,.pdf
You have isolated a new virus, determined it has a lipid envelope,.pdfYou have isolated a new virus, determined it has a lipid envelope,.pdf
You have isolated a new virus, determined it has a lipid envelope,.pdffckindswear
 
Write the Java source code necessary to build a solution for the pro.pdf
Write the Java source code necessary to build a solution for the pro.pdfWrite the Java source code necessary to build a solution for the pro.pdf
Write the Java source code necessary to build a solution for the pro.pdffckindswear
 

More from fckindswear (20)

Nessus is a network security toolIn a pragraph describe how it is .pdf
Nessus is a network security toolIn a pragraph describe how it is .pdfNessus is a network security toolIn a pragraph describe how it is .pdf
Nessus is a network security toolIn a pragraph describe how it is .pdf
 
Luthans and Doh (2012) discuss two major forms of communication flow.pdf
Luthans and Doh (2012) discuss two major forms of communication flow.pdfLuthans and Doh (2012) discuss two major forms of communication flow.pdf
Luthans and Doh (2012) discuss two major forms of communication flow.pdf
 
Is the value of the Manufacturing Plant considered a long term or a .pdf
Is the value of the Manufacturing Plant considered a long term or a .pdfIs the value of the Manufacturing Plant considered a long term or a .pdf
Is the value of the Manufacturing Plant considered a long term or a .pdf
 
Indicate whether you agree or disagree with the following statements.pdf
Indicate whether you agree or disagree with the following statements.pdfIndicate whether you agree or disagree with the following statements.pdf
Indicate whether you agree or disagree with the following statements.pdf
 
Identify any relative maxima or minima and intervals on which the fun.pdf
Identify any relative maxima or minima and intervals on which the fun.pdfIdentify any relative maxima or minima and intervals on which the fun.pdf
Identify any relative maxima or minima and intervals on which the fun.pdf
 
How exposure to an argument through mass media may have influenced o.pdf
How exposure to an argument through mass media may have influenced o.pdfHow exposure to an argument through mass media may have influenced o.pdf
How exposure to an argument through mass media may have influenced o.pdf
 
Here is the company database--comments can be addedD.pdf
Here is the company database--comments can be addedD.pdfHere is the company database--comments can be addedD.pdf
Here is the company database--comments can be addedD.pdf
 
Find the IPv6 prefix of the address 20010fc3ca540 a0 10 if the .pdf
Find the IPv6 prefix of the address 20010fc3ca540 a0 10 if the .pdfFind the IPv6 prefix of the address 20010fc3ca540 a0 10 if the .pdf
Find the IPv6 prefix of the address 20010fc3ca540 a0 10 if the .pdf
 
Explain the kinds of information that must be maintained in fixed as.pdf
Explain the kinds of information that must be maintained in fixed as.pdfExplain the kinds of information that must be maintained in fixed as.pdf
Explain the kinds of information that must be maintained in fixed as.pdf
 
Dr. P has a culture of stem cells and she wants them to specialize i.pdf
Dr. P has a culture of stem cells and she wants them to specialize i.pdfDr. P has a culture of stem cells and she wants them to specialize i.pdf
Dr. P has a culture of stem cells and she wants them to specialize i.pdf
 
Describe two ecological roles of fungi. Related concepts decomposer.pdf
Describe two ecological roles of fungi. Related concepts decomposer.pdfDescribe two ecological roles of fungi. Related concepts decomposer.pdf
Describe two ecological roles of fungi. Related concepts decomposer.pdf
 
Differential equations using phase plane analysis. Task 1 (Romeo .pdf
Differential equations using phase plane analysis. Task 1 (Romeo .pdfDifferential equations using phase plane analysis. Task 1 (Romeo .pdf
Differential equations using phase plane analysis. Task 1 (Romeo .pdf
 
Develop a stack in c with dynamic memory allocation. Use the followi.pdf
Develop a stack in c with dynamic memory allocation. Use the followi.pdfDevelop a stack in c with dynamic memory allocation. Use the followi.pdf
Develop a stack in c with dynamic memory allocation. Use the followi.pdf
 
Define a struct type that represents a smartphone. The struct should.pdf
Define a struct type that represents a smartphone. The struct should.pdfDefine a struct type that represents a smartphone. The struct should.pdf
Define a struct type that represents a smartphone. The struct should.pdf
 
Changes in the economy have determined that for the EZ shipping comp.pdf
Changes in the economy have determined that for the EZ shipping comp.pdfChanges in the economy have determined that for the EZ shipping comp.pdf
Changes in the economy have determined that for the EZ shipping comp.pdf
 
Broadly speaking, the economy consists of households, firms, governm.pdf
Broadly speaking, the economy consists of households, firms, governm.pdfBroadly speaking, the economy consists of households, firms, governm.pdf
Broadly speaking, the economy consists of households, firms, governm.pdf
 
A committee consists of 13 Republicans and 16 Democrats. How many dif.pdf
A committee consists of 13 Republicans and 16 Democrats. How many dif.pdfA committee consists of 13 Republicans and 16 Democrats. How many dif.pdf
A committee consists of 13 Republicans and 16 Democrats. How many dif.pdf
 
2. July 01 Record the dividend received from the foreign subsidiary..pdf
2. July 01 Record the dividend received from the foreign subsidiary..pdf2. July 01 Record the dividend received from the foreign subsidiary..pdf
2. July 01 Record the dividend received from the foreign subsidiary..pdf
 
You have isolated a new virus, determined it has a lipid envelope,.pdf
You have isolated a new virus, determined it has a lipid envelope,.pdfYou have isolated a new virus, determined it has a lipid envelope,.pdf
You have isolated a new virus, determined it has a lipid envelope,.pdf
 
Write the Java source code necessary to build a solution for the pro.pdf
Write the Java source code necessary to build a solution for the pro.pdfWrite the Java source code necessary to build a solution for the pro.pdf
Write the Java source code necessary to build a solution for the pro.pdf
 

Recently uploaded

DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayMakMakNepo
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationAadityaSharma884161
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxLigayaBacuel1
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 

Recently uploaded (20)

Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up Friday
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint Presentation
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 

#include stdio.h #include string.h Read before you start .pdf

  • 1. #include #include // Read before you start: // Do not modify any part of this program that you are given. Doing so may cause you to fail automated test cases. // You are given a partially complete program. Your job is to complete the functions in order for this program to work successfully. // You should complete this homework assignment using Microsoft Visual Studios 2013 (or a later version). // All instructions are given above the required functions, please read them and follow them carefully. // If you modify the function return types or parameters, you will fail the automated test cases. // You can assume that all inputs are valid. Ex: If prompted for a char, the input will be a char. // Global Macro Values #define NUM_STRINGS 5 #define STRING_LENGTH 32 // Forward Declarations void frequency(char[NUM_STRINGS][STRING_LENGTH],char); void remove_Number(char[NUM_STRINGS][STRING_LENGTH]); void swapStrings(char[STRING_LENGTH], char[STRING_LENGTH]); void sortStrings(char[NUM_STRINGS][STRING_LENGTH]); void printStrings(char[NUM_STRINGS][STRING_LENGTH]); int alpha_Counter(char[STRING_LENGTH]); int isAPalindrome(char[STRING_LENGTH]); void addLetter(char[STRING_LENGTH], char, int); // Problem 1: frequency (5 points) // Rewrite this function to perform the same task as in hw03, using only pointer operations. // You must use pointer operations only. If you use array operations, you will recieve no credit for this part. // You may use the code you submitted for hw03 or you may use the solution code for hw03. // Traverse the 2D array of characters variable 'strings' and check the frequency of a particular letter or a search_alphabetin a string. // In order to check the frequency, first you need to read the search_alphabet from the user. // If the string is "hello" and the search_alphabet is l, the code will count the number of 'l's in hello. // The output of the function for the above mentioned case will be 2. //append that frequency value at the end of the string //for hello the new string will be hello2 void frequency(char strings[NUM_STRINGS][STRING_LENGTH],char search_alphabet) { } // Problem 2: remove_vowel (5 points) // Rewrite this function to perform the same task as in hw03, using only pointer operations. // You must use pointer operations only. If you use array operations, you will recieve no credit for this part. // You may use the code you submitted for hw03 or you may use the solution code for hw03. //Traverse the 2D array of characters variable 'strings' and remove all vowels from the string. // In order to remove all vowel characters, you need to check each letter of the string and decide whether its is a vowel. If so then remove it. If not then check the next character. // If the string is "hello", your result will be hll. //print the new string without vowel using problem 6. void remove_vowel(char strings[NUM_STRINGS][STRING_LENGTH]) { } void swapStrings(char string1[STRING_LENGTH], char string2[STRING_LENGTH]) { char
  • 2. temp[STRING_LENGTH]; strcpy(temp, string1); strcpy(string1, string2); strcpy(string2, temp); } // Problem 3: sortStrings (10 points) // Rewrite this function to perform the same task as in hw03, using only pointer operations. // You must use pointer operations only. If you use array operations, you will recieve no credit for this part. // You can use the swapStrings() function if you'd like, but are not required to do so. // You may use the code you submitted for hw03 or you may use the solution code for hw03. // // Sort the 5 strings contained in the 2D character array parameter labeled "strings". // Sort the strings based on their ASCII character value (use strcmp to compare strings). // See the output provided in the word document for example input and output. void sortStrings(char strings[NUM_STRINGS][STRING_LENGTH]) { } void printStrings(char strings[NUM_STRINGS][STRING_LENGTH]) { int i; for (i = 0; i < NUM_STRINGS; i++) { printf("%s ", strings[i]); } } // Problem 4: vowelCounter (10 points) // This function accepts an array of characters and returns the number of alphabets in that string (an integer). // You must use pointer operations only. If you use array operations, you will recieve no credit for this part. // you should not count any number or special character within the string int alpha_Counter(char string[STRING_LENGTH]) { } // Problem 5: isAPalindrome (10 points) // This function accepts an array of characters and returns an integer. // You must use pointer operations only. If you use array operations, you will recieve no credit for this part. // This function should return 1 (true) if the parameter 'string' is a palindrome, or 0 (false) if 'string' is not a palindrome. // A palindrome is a sequence of characters which when reversed, is the same sequence of characters. // For this assignment, you can assume that 'string' will be a single word containing only lowercase letters and no spaces. // Example Palindromes: mom, racecar, stats, rotator, deleveled int isAPalindrome(char string[STRING_LENGTH]) { } // Problem 6: addLetter (10 points) // This function accepts an array of characters as well as a character to be added to the existig string and a position where this new letter is to be added. // You must use pointer operations only. If you use array operations, you will recieve no credit for this part. // All occurances of the 'letterToBeRemoved' should be removed from character array 'string' // Example: If string = "letter", and letterToAdd = 'a'; the pos=2 after this function terminates, string should contain "leatter" void addLetter(char string[STRING_LENGTH], char letterToAdd, int pos) { } // You should study and understand how this main function works. // Do not modify it in any way, there is no implementation needed here. void main() { int selection,i; char input[STRING_LENGTH]; printf("Assignment 4: Pointer Operations "); printf("Choose one of the following: 1. Sorting Strings 2. Alphabet counter 3. Palindrome 4. Letter Addition "); scanf("%d", &selection); // store integer getchar(); // consume newline char if (selection == 1) { char
  • 3. strings[NUM_STRINGS][STRING_LENGTH]; // will store 5 strings each with a max length of 32 char search_alphabet; for (i = 0; i < NUM_STRINGS; i++) { printf(" Enter the next String: "); // prompt for string fgets(input, sizeof(input), stdin); // store input string input[strlen(input) - 1] = '0'; // convert trailing ' ' char to '0' (null terminator) strcpy(strings[i], input); // copy input to 2D strings array } printf("Enter a character for checking its frequency: "); // prompt for integer scanf("%c", &search_alphabet); // store integer frequency(strings, search_alphabet); remove_vowel(strings); printf(" The strings after vowel removal: "); printStrings(strings); sortStrings(strings); printf(" Sorted Strings: "); printStrings(strings); } else if (selection == 2) { printf(" Enter a String: "); // prompt for string fgets(input, sizeof(input), stdin); // store input string input[strlen(input) - 1] = '0'; // convert trailing ' ' char to '0' (null terminator) int numAlpha = alpha_Counter(input); printf(" There are %d alphabets in "%s"", numAlpha, input); } else if (selection == 3) { printf(" Enter a String: "); // prompt for string fgets(input, sizeof(input), stdin); // store input string input[strlen(input) - 1] = '0'; // convert trailing ' ' char to '0' (null terminator) int isPalindrome = isAPalindrome(input); if (isPalindrome) printf(" The string "%s" is a palindrome", input); else printf(" The string "%s" is not a palindrome", input); } else if (selection == 4) { printf(" Enter a String: "); // prompt for string fgets(input, sizeof(input), stdin); // store input string input[strlen(input) - 1] = '0'; // convert trailing ' ' char to '0' (null terminator) char letterToAdd; int pos; printf(" Enter a letter to be added: "); // prompt for char scanf(" %c", &letterToAdd); // store input char printf(" Enter the array position for adding the letter:"); scanf("%d",&pos); addLetter(input, letterToAdd, pos); printf(" Result: %s", input); } else { printf("Program terminating..."); } } Solution PROGRAM CODE: /* * stringManipulation.cpp * * Created on: 11-Feb-2017 * Author: kasturi
  • 4. */ #include #include #include // Read before you start: // Do not modify any part of this program that you are given. Doing so may cause you to fail automated test cases. // You are given a partially complete program. Your job is to complete the functions in order for this program to work successfully. // You should complete this homework assignment using Microsoft Visual Studios 2013 (or a later version). // All instructions are given above the required functions, please read them and follow them carefully. // If you modify the function return types or parameters, you will fail the automated test cases. // You can assume that all inputs are valid. Ex: If prompted for a char, the input will be a char. // Global Macro Values #define NUM_STRINGS 5 #define STRING_LENGTH 32 // Forward Declarations void frequency(char[NUM_STRINGS][STRING_LENGTH],char); //void remove_Number(char[NUM_STRINGS][STRING_LENGTH]); void swapStrings(char[STRING_LENGTH], char[STRING_LENGTH]); void sortStrings(char[NUM_STRINGS][STRING_LENGTH]); void printStrings(char[NUM_STRINGS][STRING_LENGTH]); int alpha_Counter(char[STRING_LENGTH]); int isAPalindrome(char[STRING_LENGTH]); void addLetter(char[STRING_LENGTH], char, int); // Problem 1: frequency (5 points) // Rewrite this function to perform the same task as in hw03, using only pointer operations. // You must use pointer operations only. If you use array operations, you will recieve no credit for this part. // You may use the code you submitted for hw03 or you may use the solution code for hw03. // Traverse the 2D array of characters variable 'strings' and check the frequency of a particular letter or a search_alphabetin a string. // In order to check the frequency, first you need to read the search_alphabet from the user.
  • 5. // If the string is "hello" and the search_alphabet is l, the code will count the number of 'l's in hello. // The output of the function for the above mentioned case will be 2. //append that frequency value at the end of the string //for hello the new string will be hello2 void frequency(char strings[NUM_STRINGS][STRING_LENGTH],char search_alphabet) { char *tobeModified = &strings[0][0]; int i=0; while(i 0) swapStrings(temp1, temp2); } temp1 += STRING_LENGTH; } } void printStrings(char strings[NUM_STRINGS][STRING_LENGTH]) { int i; for (i = 0; i < NUM_STRINGS; i++) { printf("%s ", strings[i]); } } // Problem 4: vowelCounter (10 points) // This function accepts an array of characters and returns the number of alphabets in that string (an integer). // You must use pointer operations only. If you use array operations, you will recieve no credit for this part. // you should not count any number or special character within the string int alpha_Counter(char string[STRING_LENGTH]) { int counter = 0, i=0; char *pointer = &string[0]; while(i