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

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?
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...
I am trying to write a UDP socket program in which there is a server program...
I am trying to write a UDP socket program in which there is a server program and a client program. This is what I have but I can't figure out where I am going wrong. This is the input and expected output: > gcc udpclient.c –o clientout > gcc udpserver.c –o serverout > ./serverout 52007 ‘to celebrate’ & > ./clientout odin 52007 ‘Today is a good day’ Today is a good day to celebrate //UDP echo client program #include #include...
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...
Hi, I am running C# in Vis. Studio 2019 community. Trying to get my program to...
Hi, I am running C# in Vis. Studio 2019 community. Trying to get my program to populate the username in the program after entered. I can enter a name and the three scores and average them as the program needs but the name is not adding next to the "Students name: " in the program. Any help would be appreciated and please place a note for what I am doing wrong. Thank you using System; using System.Collections.Generic; using System.Linq; using...
I am trying to create bit masks to create a new binary number with the original...
I am trying to create bit masks to create a new binary number with the original bits' orders turned around, and concataneted. For example, int test=0b01100010001010001001(20 bits) now, I need bit masking to make it: int result = 20th bit, 10-1 bits, 11th bit, 19-12 bits, in this order. So in this case, answer would be: 0(20th bit)10100010(10-1 bits)0(11th bit)1011000100(19-12 bits). Im trying to do something like int res |= test & 0x7F800; res |= test& 0x400; Can't seem to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT