Advertisement
tareq1988

Abbreviate string

Nov 23rd, 2011
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.85 KB | None | 0 0
  1. /**
  2.  * Subject: Automata Theory and Compiler Design
  3.  * Author: Tareq Hasan <http://tareq.weDevs.com>
  4.  *
  5.  * Experiment: 3
  6.  * Write a Program that read a string and abbreviates
  7.  *
  8.  * Sample Input: CSE-307
  9.  * Sample Output: Computer Science & Engineering, 3rd Year, Artifitial Inteligence
  10.  */
  11.  
  12. #include <iostream>
  13. #include <stdio.h>
  14. #include <string.h>
  15. #include <ctype.h>
  16. using namespace std;
  17.  
  18. #define SUB_MAX 5
  19.  
  20. int main() {
  21.     char input[20];
  22.    
  23.     cout << "Enter subject code: ";
  24.     cin >> input;
  25.    
  26.     string subjects[][SUB_MAX] = {{
  27.         "Introduction to Programming with C and C++ ",
  28.         "Digital Systems",
  29.         "Computer Fundamentals",
  30.         "Electronics and Electrical Circuits",
  31.         "English"
  32.     }, {
  33.         "Object Oriented Programming",
  34.         "Data StructureJ",
  35.         "Algorithms",
  36.         "Computer Architecture and Organization",
  37.         "Numerical Methods"
  38.     }, {
  39.         "DBMS",
  40.         "Network",
  41.         "Automata theory and Compiler Design",
  42.         "Operating System",
  43.         "Assembly Language"
  44.     }, {
  45.         "Digital Image Processing",
  46.         "Computer Simulation and Modelling",
  47.         "E-Commerce and Web Engineering",
  48.         "Software Engineering",
  49.         "System Analysis and Design"
  50.     }};
  51.    
  52.     string years[] = { "1st Year", "2nd Year", "3rd Year", "4th Year" };
  53.    
  54.     char *token = strtok( input, "-" );
  55.     while( token != NULL ) {
  56.        
  57.         if( strcmp( token, "CSE") ) {
  58.             cout << "Computer Science & Engineering, ";
  59.         }
  60.        
  61.         if( isdigit( token[0] ) ) {
  62.             cout << years[token[0]-49] << ", ";
  63.         }
  64.        
  65.         if( isdigit( token[2] ) ) {
  66.             cout << subjects[token[0]-49][token[2]-49] << endl;
  67.         }
  68.        
  69.         token = strtok( NULL, "-" );
  70.     }
  71.        
  72.     return 0;
  73. }
  74.  
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement