If Statement and Switch Statement Program

My teacher assigned me a program in which I have to make a switch statement version of a past program we completed. Can anyone help me convert it?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/// Lower Case to Upper Case Program CSC 101
#include <iostream>

using namespace std;

bool is_upper ( char ch )
{
  static char upper[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

  for ( int i = 0; upper[i] != '\0'; i++ ) {
    if ( ch == upper[i] )
      return true;
  }

  return false;
}

bool is_lower ( char ch )
{
  static char lower[] = "abcdefghijklmnopqrstuvwxyz";

  for ( int i = 0; lower[i] != '\0'; i++ ) {
    if ( ch == lower[i] )
      return true;
  }

  return false;
}

char to_lower ( char ch )
{
  static char upper[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  static char lower[] = "abcdefghijklmnopqrstuvwxyz";

  for ( int i = 0; upper[i] != '\0'; i++ ) {
    if ( ch == upper[i] )
      return lower[i];
  }

  return ch;
}

char to_upper ( char ch )
{
  static char upper[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  static char lower[] = "abcdefghijklmnopqrstuvwxyz";

  for ( int i = 0; lower[i] != '\0'; i++ ) {
    if ( ch == lower[i] )
      return upper[i];
  }

  return ch;
}

int main()
{
  char ch;

  cout<<"Enter a Letter: ";
  cin>> ch;

  if ( is_upper ( ch ) )
    cout<<"The lower case equivalent will be "<< to_lower ( ch ) <<endl;
  else if ( is_lower ( ch ) )
    cout<<"The upper case equivalent will be "<< to_upper ( ch ) <<endl;
  else
    cout<<"The character you entered is not a letter"<<endl;

  
  while ( cin.get ( ch ) && ch != '\n' )
    ;

  cin.get();
}
Last edited on
Topic archived. No new replies allowed.