Question

In: Computer Science

Question 1: Write a program in C++ using multi filing which means 3 files ( main...

Question 1: Write a program in C++ using multi filing which means 3 files ( main file, header file, and functions file) and attached screenshots as well. Attempt the Question completely which contain a and b parts

a) Write a program that takes a number from the user and checks whether the number entered validates the given format: “0322-5441576”, xxxx-xxxxxxx where “x” implies the digits only and first two digits are 0 and 3 respectively. The program also identifies the Network of the given number. (Use of string related functions is a must)

b) Write a program that takes a string from the user, identifies and counts all unique characters in that given string. You are bound to use only built-in string functions where necessary. For identification of unique characters and for counting of the characters make separate functions.

For character identification

Develop a program that takes a string argument, and returns an array containing all unique characters.

For character counting

Develop a program that takes an array returned from above function as an argument along with the given string and return an array containing the total count of each uniquely identified character present in the argument array.

Note: kindly write a proper code of program mention in Question and answer complete Question along with both parts and screenshots Thanks.....

Solutions

Expert Solution

a)

// // a) Write a program that takes a number from the user
//  and checks whether the number entered validates the given format: “0322-5441576”,
//   xxxx-xxxxxxx where “x” implies the digits only and first two
//    digits are 0 and 3 respectively.
//     The program also identifies the Network of the given number.
//      (Use of string related functions is a must)


#include <iostream>
#include <string>
using namespace std;

int main(){
        string number = "";
        cout << "Please enter the number: ";
        cin >> number;
        if(number[0] != '0' || number[1] != '3' || number.size() != 12 || 
                number[4]!= '-'){
                cout << "Not in the format 03xx-xxxxxxx, Exiting..."<< endl;
                exit(1);
        }
        else{
                cout << "Number is in the required format!\n";
        }
        return 0;       
}

b)

/*
Write a program that takes a string from the user, identifies and counts
all unique characters in that given string. You are bound to use only
built-in string functions where necessary. For identification of unique
characters and for counting of the characters make separate functions.

For character identification

Develop a program that takes a string argument, and returns an array containing all unique characters.

For character counting

Develop a program that takes an array returned from above function as an argument along with the given string and return an array containing the total count of each uniquely identified character present in the argument array.
*/

#include <bits/stdc++.h>
using namespace std;

vector <char> getAllUniqueChars(string& s){
        unordered_map <char,bool> umap;
        for(auto x:s){
                if(umap.find(x) != umap.end())
                        umap[x] = 1;
        }
        vector <char> uniqueChars;
        for(auto x:umap)
                uniqueChars.push_back(x.first);
        return uniqueChars;
}

unordered_map <char,int> getCountOfChars(vector <char>&  uniquechars,
        string input_string) {
        unordered_map <char,int> umap;
        for(auto x:input_string)
                umap[x]++;
        return umap;
}
int main() {
        string input_string = "";
        getline(cin, input_string);
        vector <char> uniquechars = getAllUniqueChars(input_string);
        unordered_map <char, int> countArray = getCountOfChars(uniquechars, input_string);
        for(auto x:countArray)
                cout << x.first << " --> " << x.second << endl;
        return 0;
}

Related Solutions

Write a program in C++ using the following 2 Files: Book.h and Source.cpp 1.)   In Book.h,...
Write a program in C++ using the following 2 Files: Book.h and Source.cpp 1.)   In Book.h, declare a struct Book with the following variables: - isbn:   string - title:    string - price: float 2.)   In main (Source.cpp), declare a Book object named: book - Use an initialization list to initialize the object with these values:           isbn à 13-12345-01           title à   “Great Gatsby”           price à 14.50 3.)   Pass the Book object to a function named: showBook - The...
C++ Goals: Write a program that works with binary files. Write a program that writes and...
C++ Goals: Write a program that works with binary files. Write a program that writes and reads arrays to and from binary files. Gain further experience with functions. Array/File Functions Write a function named arrayToFile. The function should accept three arguments: the name of file, a pointer to an int array, and the size of the array. The function should open the specified file in binary made, write the contents into the array, and then close the file. write another...
Edit question Write a program that merges two files as follows. The two files are in...
Edit question Write a program that merges two files as follows. The two files are in the docsharing which you can download it. One file will contain usernames(usernames.txt):foster001smith023nyuyen002...The other file will contain passwords(passwords.txt):x34rdf3ep43e4rddw32eds22...The program should create a third file matching username and passwords(usernamesPasswords.txt):foster001x34rdf3esmith023p43e4rddnyuyen002w32eds22......Give the user of your programs the option of displaying you output file. CAN ANYONE SOLVE THIS IN C
Using C Language Write a program segment that computes 1 + 2 + 3 + ......
Using C Language Write a program segment that computes 1 + 2 + 3 + ... + ( n - 1) + n , where n is a data value. Follow the loop body with an if statement that compares this value to (n * (n + 1)) / 2 and displays a message that indicates whether the values are the same or different. Please give me code to just copy and paste
Write a C++ program which consists of several functions besides the main() function. The main() function,...
Write a C++ program which consists of several functions besides the main() function. The main() function, which shall ask for input from the user (ProcessCommand() does this) to compute the following: SumProductDifference and Power. There should be a well designed user interface. A void function called SumProductDifference(int, int, int&, int&, int&), that computes the sum, product, and difference of it two input arguments, and passes the sum, product, and difference by-reference. A value-returning function called Power(int a, int b) that...
Write an entire program (with a main function and necessary header files included) that declares an...
Write an entire program (with a main function and necessary header files included) that declares an 80 byte character buffer, prompts a user to enter a single word (no spaces) from the default input device (e.g. the keyboard), which is stored in the buffer, and then reverses the string while overwriting the buffer. Print the sting before and after the reversal. The program transcript should resemble the following output: $ ./program.exe enter string: nvidia before: nvidia after: aidivn in C
Correct C++ function and main files separately for the following question and its subparts. 1-aGiven a...
Correct C++ function and main files separately for the following question and its subparts. 1-aGiven a matrix of integers, count the amount of times each number 0-9 appears. Print out your results on one line in the following form: 0:number of zeros;1:number of ones;2:number of twos;3:number of threes;4:number of fours;5:number of fives;6:number of sixes;7:number of sevens;8:number of eights;9:number of nines; For example, if you are passed an identify matrix, it contains 12 zeros and 4 ones and no other numbers...
IN C LANGUAGE: Write a multi-threaded Linux program that synchronizes it's threads to write to a...
IN C LANGUAGE: Write a multi-threaded Linux program that synchronizes it's threads to write to a file without the file becoming corrupted. To do this, your program will create three threads which write strings to the same file. Each thread will randomly write a selection of strings to the file at random intervals. When finished, the file will contain all the strings written correctly to the file. You may use mutexes, semaphores, or a monitor your write on your own....
Write a program in c++, with at least four functions, including main, which must do the...
Write a program in c++, with at least four functions, including main, which must do the following: Ask user whether they want to encode or decode a message – if no, then terminate Take the input string from the user, store it in dynamic memory (use new) As appropriate, encode or decode the message using Rot13. Output the encoded/decoded message Delete the input string from dynamic memory (use delete) Input will be a string of no more than 25 characters....
Program must be in C++! Write a program which: Write a program which uses the following...
Program must be in C++! Write a program which: Write a program which uses the following arrays: empID: An array of 7 integers to hold employee identification numbers. The array should be initialized with the following values: 1, 2, 3, 4, 5, 6, 7. Hours: an array of seven integers to hold the number of hours worked by each employee. payRate: an array of seven doubles to hold each employee’s hourly pay rate. Wages: an array of seven doubles to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT