Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A top-level domain (TLD) name is the last part of an Internet domain name like .com in example.com. A core generic top-level domain (core gTLD)

A top-level domain (TLD) name is the last part of an Internet domain name like .com in example.com. A core generic top-level domain (core gTLD) is a TLD that is either .com, .net, .org, or .info. A second-level domain is a single name that precedes a TLD as in apple in apple.com

The following program uses a loop to repeatedly prompt for a domain name, and indicates whether that domain name consists of a second-level domain followed by a core gTLD. An example of a valid domain name for this program is apple.com. An invalid domain name for this program is support.apple.com because the name contains two periods. The program ends when the user presses just the Enter key in response to a prompt.

Run the program and enter domain names to validate. Note that even valid input is flagged as invalid.

Change the program to validate a domain name. A valid domain name for this program has a second-level domain followed by a core gTLD. Run the program again.

#include #include using namespace std; int main() { string inputName = ""; string searchName = ""; string coreGtld1 = ".com"; string coreGtld2 = ".net"; string coreGtld3 = ".org"; string coreGtld4 = ".info"; string theTld = ""; bool isCoreGtld = false; // FIXME: Add variable periodCounter to count periods in a domain name int periodPosition = 0; // Position of the period in the domain name int j = 0; cout << endl << "Enter the next domain name ( to exit): " << endl; cin >> inputName; while (inputName.length() > 0) { searchName = inputName; for (j = 0; j < inputName.length(); ++j) { searchName.at(j) = tolower(inputName.at(j)); } isCoreGtld = false; // FIXME: Write a for loop using variable i to store in periodCounter the // number of periods in searchName. Store the position of the period in // PeriodPosition. If searchName has exactly one period and searchName's // first character is not a period, determine whether searchName has a // valid core gTLD by extracting the domain name into variable coreGtld // and comparing the name with valid core gTLDs. // Extract the top-level domain name starting at the period's position. // Ex: If searchName = "example.com", the next statement extracts ".com" theTld = searchName.substr(periodPosition); if (theTld == coreGtld1) { isCoreGtld = true; } else if (theTld == coreGtld2) { isCoreGtld = true; } else if (theTld == coreGtld3) { isCoreGtld = true; } else if (theTld == coreGtld4) { isCoreGtld = true; } else { isCoreGtld = false; } cout << "\"" << inputName << "\" "; if (isCoreGtld) { cout << "is a second-level domain followed by a core gTLD of \"" << theTld << "\"." << endl; } else { cout << "is not a second-level domain followed by a core gTLD." << endl; } cout << endl << "Enter the next domain name (or to exit): " << endl; inputName = ""; cin >> inputName; } return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David J. Auer David M. Kroenke

13th Edition

B01366W6DS, 978-0133058352

More Books

Students also viewed these Databases questions

Question

43. Draw a full-adder using only NAND gates.

Answered: 1 week ago