In: Computer Science
I am trying to create a makefile for the following program in Unix. The C++ program I am trying to run is presented here. I was wondering if you could help me create a makefile for the following C++ file in Unix and show screenshots of the process? I am doing this all in blue on putty and not in Ubuntu, so i don't have the luxury of viewing the files on my computer, or I don't know how to anyway
Program:
//main.cpp
#include <iostream>
using namespace std;
int main() {
string s;
char ch;
int vowels = 0, consonants = 0, digits = 0,
specialCharacters = 0;
getline(cin, s);
for (int i = 0; i < s.length(); i++)
{
ch = s[i];
if ((ch >= 'a'
&& ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
{
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u'
|| ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U')
{
vowels += 1;
}
else {
consonants += 1;
}
}
else if (ch >= '0'
&& ch <= '9') {
digits += 1;
}
else {
specialCharacters += 1;
}
}
cout << "Vowels: " << vowels
<< endl;
cout << "Consonants: " << consonants
<< endl;
cout << "Digits: " << digits
<< endl;
cout << "Special characters: " <<
specialCharacters << endl;
return 0;
}
1. Copy the programs in the specific files.
2. Make sure that all files are in the same location.
3. Now open terminal and compile the files as follows
c++ main.cpp hello.cpp program.cpp -o hello
./hello
main.cpp
#include <iostream>
using namespace std;
#include "functions.h"
int main(){
Hello_World();
cout << endl;
My_Program();
return 0;
}
hello.cpp
#include <iostream>
using namespace std;
#include "functions.h"
void Hello_World(){
cout << "Hello World!";
}
program.cpp
#include "functions.h"
#include <iostream>
using namespace std;
void My_Program(){
string s;
char ch;
int vowels = 0, consonants = 0, digits = 0,
specialCharacters = 0;
getline(cin, s);
for (int i = 0; i < s.length();
i++) {
ch = s[i];
if ((ch >= 'a'
&& ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
{
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u'
|| ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U')
{
vowels += 1;
}
else {
consonants += 1;
}
}
else if (ch >= '0'
&& ch <= '9') {
digits += 1;
}
else {
specialCharacters += 1;
}
}
cout << "Vowels: " <<
vowels << endl;
cout << "Consonants: " << consonants
<< endl;
cout << "Digits: " << digits
<< endl;
cout << "Special characters: " <<
specialCharacters << endl;
}
functions.h
void Hello_World();
void My_Program();