Sie sind auf Seite 1von 5

COMPE

271 Homework - 1 Due before January 25, 11:59 PM. The following set of programming assignments are intended to facilitate learning the Eclipse IDE and refreshing C or C++ programming skills. Please write all functions required and return them on blackboard in a single file named homework1_yourredID.c . Please note that this file should contain only the functions written. Please do not change the names of the functions or number of arguments since the programs will be tested using automated testing software. The name of the file to be uploaded on Blackboard : homework1_yourredID.c Functions to be implemented. 1- int reverseString(char *mystring) 2- int isAlphabetic(char *myString) 3- computeFrequency(int *scores, int *freq, int N) ; Please note that no other form of homeworks accepted other than submitting on blackboard. Homeworks that do not comply with the file and function naming rules may not be graded. Please make sure you test your functions before submitting.

Question 1: The following C main function calls a function named reverseString to reverse the order of the characters in a string passed as argument. Write the C function named reverseString to reverse the string passed as argument. The function reverseString returns the number of characters in the string in addition to reversing the string passed. #include "stdafx.h" int main(int argc, char* argv[]) { int numchar; char mystring = This is the string to be printed in reverse order; numchar = reverseString(mystring); puts(Reversed String is ); puts(mystring); } int { reverseString(char *mystring) // PLEASE COMPLETE THE FUNCTION

Question 2: The following C program calls a function isAlphabetic to determine is a string passed contains all alphabetic characters (letters from A through Z). Write the function isAlphabetic in C or C++ by following the information provided in the main function given below. A copy of the ascii table is given below. #include <stdio.h> #include <stdlib.h> int main(void) { int value; char c='Z'; char alph[30]="there is a PROF 1 var orada"; char freq[27]; int i; // The function isAlphabetic will accept a string and test each character to // verify if it is an alphabetic character ( A through Z , lowercase or uppercase) // if all characters are alphabetic characters then the function returns 0. // If a nonalphabetic character is found, it will return the index of the nonalpabetic // character. value = isAlphabetic(alph); if (value == 0) printf("\n The string is alphabetic"); else printf("Non alphabetic character is detected at position %d\n",value); return EXIT_SUCCESS; } int isAlphabetic(char *myString)

Question 3 : Given an array (int scores[N]) containing N integer midterm scores between 0 and 9, write a C Function that computes how many of the scores are 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9. The function should get two array arguments one containing the scores and the second containing the frequencies. The function will be called from the main program with the following command. computeFrequency(int *scores, int *freq, int N) ;

Das könnte Ihnen auch gefallen