CS102 summer programming assignment

Post all your queries related to CS 102 course here...

CS102 summer programming assignment

Postby Tara » Mon Jul 20, 2009 11:18 am

Hi... our assignment is, in part, to create an array of the ICAO phonetic alphabet (Alpha Bravo Charlie etc) and to then let the program user enter a word, which is read as a string, and then the program translates the word into the ICAO alphabet. Each letter is supposed to be read individually, so that it translates C3PO as Charlie 3 Papa Oscar.

I cannot for the life of me figure out how to do this. How do I get it to read the individual letters of a string and translate them??? I can do everything else the program wants! I know it has something to do with subtracting the letters... as in C-A would be 2, and Charlie is in position 2 in the array... but I don't quite get how to do this.

Thanks!
Tara
 
Posts: 3
Joined: Mon Jun 08, 2009 11:42 am

Re: CS102 summer programming assignment

Postby Ajinkya Kulkarni » Mon Jul 20, 2009 12:39 pm

Hi, Thanks for your post. I will look into an assignment and will get back to you soon.
User avatar
Ajinkya Kulkarni
Help Desk Administrator
 
Posts: 32
Joined: Fri Mar 13, 2009 6:22 pm

Re: CS102 summer programming assignment

Postby Ajinkya Kulkarni » Mon Jul 20, 2009 3:24 pm

Hi,

Please have a look on the following code segment
Code: Select all
#include<stdio.h>

void main()
{
    char ICAO[26][10]={ 
        
"Alpha",
        "Bravo" ,
         "Charlie",
        "Delta",
        "Echo",
        "Foxtrot",
        "Golf",
        "Hotel",
        "India",
        "Juliet",
        "Kilo",
        "Lima",
        "Mike",
        "November",
        "Oscar",
        "Papa",
        "Quebec",
        "Romeo",
        "Sierra",
        "Tango",
        "Uniform",
        "Victor",
        "Whiskey",
        "X-ray",
        "Yankee",
        "Zulu"};

  char userInput[20];  //for storing a user input string of length 20 (u can change it)
  int position;   
  char currentLetter 
;
  int i,j; //for-loop counter 
  scanf("%s",&userInput);  //notice %s is used to get whole string at once


 //you need to write logic to change each charcter in user's input string to upper case


for(i=0;i<20;i++)  // 20 because = userInput[20]
{
currentLetter=userInput[i];

if (currentLetter==0) //0 will determine the end of user string if user's string is less than 20 characters
break;

position = currentLetter - 'A';
if (currentLetter>47 && currentLetter< 58)
{
    //ASCII codes for 0 to 9 are from 48 to 57
    //if currentLetter is numeric then directly print it
printf("%c ",currentLetter);

}
else
{
    //otherwise print the corresponding entry from an array
printf("%s ",ICAO[position]);
}



}

     

} 


and on following output
2009-07-20_1509.png
2009-07-20_1509.png (11.4 KiB) Viewed 1497 times


Also please have a look on execution program too



Please let me know whether this helps or not, and let me know if you need any help in understanding the code which I posted above

Thanks for using CS Online Help Desk
User avatar
Ajinkya Kulkarni
Help Desk Administrator
 
Posts: 32
Joined: Fri Mar 13, 2009 6:22 pm


Return to CS 102 : INTRO TO C PROGRAMMING

Who is online

Users browsing this forum: No registered users and 1 guest

cron