I need help with this assignment in C++, please!
*** The instructions and programming style details are crucial for this assignment!
// C++ program to read a list of phone calls from file and display in formatted manner on console
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
#include <sstream>
using namespace std;
// function declaration
bool isTimeValid(string start_time);
bool isPhoneNumValid(string phone_number);
bool isDurationValid(string duration);
string formatTime(string duration);
string getCountry(string phone_number);
string getLocalPhone(string phone_number);
int stringToInteger(string str);
int main() {
string filename;
string start_time, phone_number, duration;
cout<<"File Name:";
cin>>filename;
ifstream fin(filename.c_str());
if(fin.is_open())
{
cout<<left<<setw(10)<<"Time"<<left<<setw(9)<<"Country"<<left<<setw(16)<<"Phone Number"<<left<<"Duration"<<endl;
while(!fin.eof())
{
fin>>start_time>>phone_number>>duration;
if(isTimeValid(start_time)){
string modTime = start_time.substr(0,2)+":"+start_time.substr(2,2)+":"+start_time.substr(4);
cout<<left<<setw(8)<<modTime<<" ";
}else
cout<<left<<setw(10)<<"ERROR";
if(isPhoneNumValid(phone_number))
{
cout<<left<<setw(2)<<getCountry(phone_number)<<" "<<left<<setw(14)<<getLocalPhone(phone_number)<<" ";
}else
cout<<left<<setw(9)<<"ERROR"<<left<<setw(16)<<"ERROR";
if(isDurationValid(duration))
cout<<left<<formatTime(duration);
else
cout<<left<<"-1:-1";
cout<<endl;
}
}else
cout<<"Failed to open file"<<endl;
return 0;
}
// function to check if the start time is valid
bool isTimeValid(string start_time)
{
if(start_time.length() != 6)
return false;
for(size_t i=0;i<start_time.length();i++)
if(start_time[i] < '0' || start_time[0] >'9')
return false;
int hour = stringToInteger(start_time.substr(0,2));
int min = stringToInteger(start_time.substr(2,2));
int sec = stringToInteger(start_time.substr(4,2));
if(hour < 0 || hour > 23 || min < 0 || min > 59 || sec < 0 || sec > 59)
return false;
return true;
}
// function to check if the phone number is valid
bool isPhoneNumValid(string phone_number)
{
if(phone_number.length() != 12)
return false;
if((phone_number.substr(0,2).compare("+1") != 0) && (phone_number.substr(0,3).compare("+33") != 0) && (phone_number.substr(0,4).compare("+852") != 0))
return false;
return true;
}
// function to check if the duration is valid
bool isDurationValid(string duration)
{
if(duration.length() > 9)
return false;
for(size_t i=0;i<duration.length();i++)
if(duration[i] < '0' || duration[0] >'9')
return false;
return true;
}
// function format and return the duration
string formatTime(string duration)
{
int dur = stringToInteger(duration);
int mins = dur/60;
int secs = dur - (mins*60);
stringstream minss, secss;
minss<<mins;
secss<<setw(2)<<setfill('0')<<secs;
string retStr = minss.str()+":"+secss.str();
return retStr;
}
// function to format and return the country of the associated phone number
string getCountry(string phone_number)
{
if(phone_number.substr(0,2).compare("+1") == 0)
return "NA";
else if(phone_number.substr(0,3).compare("+33") == 0)
return "FR";
else
return "HK";
}
// function to format and return the local phone number
string getLocalPhone(string phone_number)
{
if(phone_number.substr(0,2).compare("+1") == 0)
return("("+phone_number.substr(2,3)+")-"+phone_number.substr(5,3)+"-"+phone_number.substr(8));
else if(phone_number.substr(0,3).compare("+33") == 0)
{
string mod_phone = "0"+phone_number.substr(3,1);
size_t index = 4;
while(index < phone_number.length())
{
mod_phone = mod_phone +" "+ phone_number.substr(index,2);
index = index + 2;
}
return mod_phone;
}else
{
return(phone_number.substr(4,4)+" "+phone_number.substr(8));
}
}
// function to convert string to integer
int stringToInteger(string str)
{
return stoi(str);
}
//end of program
Output:
Input file:
Output:
I need help with this assignment in C++, please! *** The instructions and programming style detai...
I need help with the following code... Instructions: This lab builds on the skills from Lab 2c, in which you read data values from a file and kept a count of the number of invalid values. In this lab, your program will be using the same code to read each data entry from the file, but you will also save each value in an array named allMags after each is read in. When all values in the file have been...
I need help programming this question using C language. This program uses input data entered in command line at the same time when the command or .exe file is entered. They are called command-line arguments. Because everything entered in command line is taken as a string, these arguments including the command itself or the .exe file name are stored in an array of char pointers, each pointer points to the first character of a string (i.e., argument). The inputs can...
can you please follow all the instructions ? The answers that I got has either missing range for loop or one funtion . Read the instructions carefully. At least 10% will be deducted if the instructions are not followed. For general lab requirements, see General Lab Requirements. Do not prompt the user for input during the execution of your program. Do not pause at the end of the execution waiting for the user's input. Notes 1. Your program should use...
Write a program **(IN C)** that displays all the phone numbers in a file that match the area code that the user is searching for. The program prompts the user to enter the phone number and the name of a file. The program writes the matching phone numbers to the output file. For example, Enter the file name: phone_numbers.txt Enter the area code: 813 Output: encoded words are written to file: 813_phone_numbers.txt The program reads the content of the file...
C++ assignment help! The instructions are below, i included the main driver, i just need help with calling the functions in the main function This assignment will access your skills using C++ strings and dynamic arrays. After completing this assignment you will be able to do the following: (1) allocate memory dynamically, (2) implement a default constructor, (3) insert and remove an item from an unsorted dynamic array of strings, (4) use the string class member functions, (5) implement a...
Help with programming in C++
Phase 1 is complete, please help with phase 2. Thank you.
Phase 1
You must design 3 algorithms, and provide
both a flow chart and pseudo code for the
algorithms.
Algorithm descriptions:
Given an integer parameter named current_number
and two constant global variables:
const int MIN_NUMBER = 1;
const int MAX_NUMBER = 8;
Create an algorithm named forward, that will
advance ONE value through a sequence of numbers 1,
2, 3 ... MAX_NUMBER. In...
C++ programming help.
The only change you have to make is in current program,
where it says "your code goes here", do not make any changes to any
other files, they are just there to show you. This
code should be written for arbitrary data, not specifically for
this sequence of data. The only place you need to
write a code is marked YOUR CODE GOES HERE.
You have been supplied a file with data in it (data2.txt). The
line...
C++ programming For this assignment, write a program that will act as a geometry calculator. The program will be menu-driven and should continue to execute as long as the user wants to continue. Basic Program Logic The program should start by displaying a menu similar to the following: Geometry Calculator 1. Calculate the area of a circle 2. Calculate the area of a triangle 3. Quit Enter your choice(1-3): and get the user's choice as an integer. After the choice...
/************************************************************************************ * Program: PRG/420 Week 5 * Purpose: Week 5 Coding Assignment * Programmer: TYPE YOUR NAME HERE * Class: PRG/420 * Creation Date: TYPE TODAY'S DATE HERE ************************************************************************************* * Program Summary: * This program converts a given date to a string. * The code includes exception handling for a ParseException. ************************************************************************************/ package prg420week5_codingassignment; import java.util.*; // wildcard to import all the util. classes import java.text.*; // wildcard to import all the text classes public class PRG420Week5_CodingAssignment { public static...
I need the following written in Java please, thank you
'
We want you to implement a java class that will show details on users and throw exceptions where needed. The following requirements specify what fields you are expected to implement in your User class: - A private String firstName that specifies the first name of the user - A private String lastName that specifies the last name of the user - A private int age that specifies user's age...