// NAME     : LIM SIN JIE
//IC NUMBER : 000521130688
//NAME      : LUHUNG AKSYARA ADJI
//IC NUMBER : 201908M10180
//SECTION   : 03
//DATE      : 29-11-2019
//COURSE    : SECJ1013 PROGRAMMING TECHNIQUE 1
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cctype>
#define MAX 100
using namespace std;

void displayMenu();
void countWords();
void calcElecRest();
float calc_Q(float);

void displayMenu()
{
	int choice;
	cout<<"::MID TERM TEST SYSTEM MENU::"<< endl;
	cout<<"   (1) Words count calculator" << endl;
	cout<<"   (2) Electric charges calculator" <<endl;
	cout<<"   (3) Quit"<<endl<<endl;
	
	cout<<"Your choice >> ";
	cin>>choice;
	cin.ignore();
	switch(choice)
	{
		case 1: countWords();
		        break;
		case 2: calcElecRest();
		        break;
		case 3: cout<<"\nThank you for using our system. . .\n";
		        exit(0);
		default: cout<<"\nINVALID INPUT IS ENTERED. PLEASE QUIT THE SYSTEM\n";
		        exit(0);	
	}	
}
void countWords()
{
	char str[MAX];
	int numWords;
	numWords=0;
	cout<<"\n\n::WORDS COUNT CALCULATOR ::"<<endl<<endl;
	
	cout<<"Enter a string: ";
	cin.getline(str,MAX);
	cout<<"\nList of words:";
	for (int i = 0; str[i]!='\0';i++)
	{
		if(isspace(str[i])||str[i] == str[0])
		{
			numWords++;
			cout<<endl;
			cout<<"   Words "<<numWords<<" >> ";
		}
		if(isalpha(str[i]))
		{
			str[i]=tolower(str[i]);
			cout<<str[i];
		}
	}
	cout<<"\n\nThe number of words = "<<numWords<<endl;	
}
void calcElecRest()
{
	float P, V, I, Q;
	
	cout<<"\n\n::ELECTRIC CHARGES CALCULATOR::"<<endl<<endl;
	cout << "Please enter the power in Watts"
	        <<"\nand the voltage (V) in kilovolts\n";
	cout<<"\n   Power(W)    = ";
	cin>>P;
	cout<<"   Voltage(kV)  = ";
	cin>>V;
	while(P<0 || V<0)
    {
    	cout<<"   Invalid input. Please try again !\n";
		cout<<"\n   Power(W)    = ";
		cin>>P;
		cout<<"   Voltage(kV)  = ";
		cin>>V;	
	}
	I = P / (V*1000);
	Q = calc_Q(I);
	
	cout<<"\nPower, P = "<<P<<" watts"<<endl;
	cout<<"Voltage, V = "<<(V*1000)<< " volts"<<endl;
	cout<<"Electric current, I = "<<I<<" amperes"<<endl;
	cout<<"Electric charge, Q = "<<Q<<" coulombs"<<endl;
}
float calc_Q(float I)
{
	float t,Q;
	cout<<"\nEnter the time of current flow, t in minutes = ";
	cin>>t;
	Q = I * t;
	return Q;
}
int main()
{
	displayMenu();
	
	return 0;
}
















