aboutsummaryrefslogtreecommitdiff
path: root/CST116F2021-Lab6/Functions.cpp
blob: 57c353edb09956cf9ad9f254ebcbf399d739ab00 (plain) (blame)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include "Header.h"

//11a
//10.10 Learn by Doing Exercises
//function getInput definition
void getInput(string studentClub, string presidentName, int numberOfStudents, string strClubIndex[10][2], int intClubIndex[], int& repeats)
{
	strClubIndex[repeats][0] = studentClub;
	strClubIndex[repeats][1] = presidentName;
	intClubIndex[repeats] = numberOfStudents;
}

//function calculateMoney definition
void calculateMoney(int intClubIndex[], int intClubMoneyIndex[], int repeats)
{
	for (int clubCount = 0; clubCount <= repeats; clubCount++)
	{
		intClubMoneyIndex[clubCount] = intClubIndex[clubCount] * 75;
	}
}

//function displayTable definition
void displayTable(string strClubIndex[10][2], int intClubIndex[], int intClubMoneyIndex[], int repeats)
{

    cout << "\n--Club Table--\n" << endl;
    cout << "Student Club";
    cout.width(10);
    cout << "President";
    cout.width(10);
    cout << "Number of Students";
    cout.width(10);
    cout << endl;

    for (int i = 0; i < repeats; i++)
    {
        cout << "| Club name: " << strClubIndex[i][0]
            << " | Club President: " << strClubIndex[i][1]
            << " | Number of Students: " << intClubIndex[i]
            << " | Club Money: " << intClubMoneyIndex[i] << " |"
            << endl;
    }

    cout << endl;
}

//11c
//function getStartup definition
char getStartup(char userString[])
{
    cout << "Welcome to the super cool string information program!\n"
        << endl
        << "Please enter your string.\n";
    cin >> userString;

    return '0';
}
//function isPalindrome definition
int isPalindrome(char userString[])
{
    //initializations
    char forward[30];
    char backward[30];
    int length = 0;
    //calculate length of userString
    while (userString[length] != '\0')
    {
        length++;
    }
    //forward to userString, backward to userString backwards
    strcpy_s(forward, 30, userString);

    strcpy_s(backward, 30, userString);

    for (int a = 0, b = (length-1); a < length; a++, b--)
    {
        backward[a] = forward[b];
    }
    //compare forward with backward
    if (strcmp(forward, backward) == 0)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

//function isAlphaStr definition
int isAlphaStr(char userString[])
{
    for (int a = 0; userString[a] != '\0'; a++)
    {
        if ((userString[a] < 65 || userString[a] > 90) && (userString[a] < 97 || userString[a] > 122))
        {
            return 0;
        }
    }
    return 1;
}

//function countChar definition
int countChar(char userString[], char& stringCheck)
{
    //initializations
    int showCt = 0;
    cout << "\nEnter a character to check number of appearances in your string: ";
    cin >> stringCheck;

    for (int a = 0; userString[a] != '\0'; a++)
    {
        if (userString[a] == stringCheck)
            {
                showCt++;
            }
    }

    return showCt;
}