Question

In: Computer Science

I am trying to create a makefile for the following program in Unix. The C++ program...

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;
}

Solutions

Expert Solution

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();


Related Solutions

I am trying to create a program That works with two other programs in c++ and...
I am trying to create a program That works with two other programs in c++ and a makefile. Only Shape.cpp can be modified. and it needs to work on a unix machine. It isn't running on my machine. And gives me an error message that it doesn't recomize cin and endl The program will accept a character and an X and Y coordinate. Dependign on the Charactor, It will then tell you what Cells that shape occupies. I almost have...
I am trying to create a basic shell program in C that runs 10 commands and...
I am trying to create a basic shell program in C that runs 10 commands and then quits. Only one word commands are required, like: cal, date, ls, ps, pwd, who, quit The part I am struggling with is passing the scanned command into my array in the child process to be executed using execvp(). Here is my code: #include <stdio.h> #include <string.h> #include<stdlib.h> #include<unistd.h> #include<sys/types.h> #include<sys/wait.h> #include<readline/readline.h> #include<readline/history.h> #define MAX_CMD_NUMBER 10 int main() {    int i;    char...
Hello, I am trying to write a C++ program that will do the following: Use the...
Hello, I am trying to write a C++ program that will do the following: Use the STL stack container in a program that reads a string, an arithmetic expression to be exact, one character at a time, and determines if the string has balanced parenthesis – that is, for each left parenthesis there is exactly one matching right parenthesis later in the string.                         Use the following strings to test your program. A+ B - C A * B / (C...
Hi I am having the following problem. At the moment I am trying to create a...
Hi I am having the following problem. At the moment I am trying to create a bode plot for the following function. G(s)=(Ks+3)/((s+2)(s+3)) Note: Not K(s+2)! I then want to plot multiple bode plots for various values of K. Eg. 1,2,3, etc. I am having two separate issues. 1. How do I define the TF with a constant K in the location required (a multiple of s in the numerator) 2. How do I create multiple bode plots for values...
I am trying to create a program that reads from a csv file and finds the...
I am trying to create a program that reads from a csv file and finds the sum of total volume in liters of liquor sold from the csv file by county and print that list out by county in descending order. Currently my program runs and gives me the right answers but it is not in descending order. I tried this:     for county, volume in sorted(sums_by_volume.items(), key=lambda x: x[1], reverse=True):         index +=1         print("{}. {} {:.2f}".format(county, sums_by_volume[county]))      When I run...
I am having a trouble with a python program. I am to create a program that...
I am having a trouble with a python program. I am to create a program that calculates the estimated hours and mintutes. Here is my code. #!/usr/bin/env python3 #Arrival Date/Time Estimator # # from datetime import datetime import locale mph = 0 miles = 0 def get_departure_time():     while True:         date_str = input("Estimated time of departure (HH:MM AM/PM): ")         try:             depart_time = datetime.strptime(date_str, "%H:%M %p")         except ValueError:             print("Invalid date format. Try again.")             continue        ...
I am trying to create a classified balance sheet and I am unsure what is involved...
I am trying to create a classified balance sheet and I am unsure what is involved when reporting the current assets, liabilities and owners equity?
I am working on a project for my Computer Science course. I am trying to create...
I am working on a project for my Computer Science course. I am trying to create a Battleship game where a user names two coordinates on a grid and is then told whether this results in a "Hit" or a "Miss". Once the ship has been hit a certain number of times (based on the size of the ship) the ship is sunk. I have written all the code but it now fails to execute when I try to run...
In trying to apply my knowledge in the real world, I am trying to create a...
In trying to apply my knowledge in the real world, I am trying to create a realistic retirement schedule. However, I am running into difficulties using both a financial calculator as well as our equations from class in doing this. I am trying to do the following: plan a retirement schedule between the ages of 25 and 70, in which I would deposit 20% of my income each year. The income starts at 80,000 with an annual growth rate of...
Professor, In trying to apply my knowledge in the real world, I am trying to create...
Professor, In trying to apply my knowledge in the real world, I am trying to create a realistic retirement schedule. However, I am running into difficulties using both a financial calculator as well as our equations from class in doing this. I am trying to do the following: plan a retirement schedule between the ages of 22 and 68, in which I would deposit 25% of my income each year. The income starts at 80,000 with an annual growth rate...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT