C++ help
Format any numerical decimal values with 2 digits after the decimal
point.
Problem description
Write the following functions as prototyped below. Do not alter the
function signatures.
/// Returns a copy of the string with its first character
capitalized and the rest lowercased.
/// @example capitalize("hELLO wORLD") returns "Hello world"
std::string capitalize(const std::string&
str);
/// Returns a copy of the string centered in a string of length
'width'.
/// Padding is done using the specified 'fillchar' (default is an
ASCII space).
/// The original string is returned if 'width' is less than or
equal to the string's length.
/// @example center("C++ is fun", 20, '*') becomes " *****C++ is
fun*****"
std::string center(const std::string& str, size_t
width, char fillchar = ' ');
/// Returns the number of vowels (a, e, i, o, u) in a string – case
insensitive
/// @example numVowels("HEllo WorlD") returns 3
int numVowels (const std::string&
str);
/// Returns a copy of the string with all the letters
converted to lowercase.
/// @example lower("heLLO WoRLD") returns "hello world"
std::string lower(const std::string&
str);
/// Reverses the order of the characters in the string
/// @example reverse("ABCD") returns "EDCBA"
void reverse(std::string& str);
/// removes vowels from a string
/// @example removeVowels("Hello wOrld") returns "Hll wrld"
std::string removeVowels(std::string&
str);
/// Returns the Scrabble(tm) word score for a string using the
point values shown in the table below:
///
/// +--------+------------------------------+
/// | Points | Letters |
/// +--------+------------------------------+
/// | 1 | A, E, I, L, N, O, R, S, T, U |
/// +--------+------------------------------+
/// | 2 | D, G |
/// +--------+------------------------------+
/// | 3 | B, C, M, P |
/// +--------+------------------------------+
/// | 4 | F, H, V, W, Y |
/// +--------+------------------------------+
/// | 5 | K |
/// +--------+------------------------------+
/// | 8 |J, X |
/// +--------+------------------------------+
/// | 10 | Q, Z |
/// +--------+------------------------------+
///
/// @example, the word "FARM" is worth 9 points in Scrabble: 4 for
the 'F',
/// 1 each for the 'A' and the 'R', and 3 for the 'M'. The function
ignores any characters other than uppercase letters in computing
the score.
int scrabble_score(const std::string&
str);
Write a client program that tests each of the
functions works as described. Hard-code test strings in your
program, i.e., do not prompt the user for any input. The output
should be labeled
to easily see what function is being tested. (Hint: you may find it
easier to write a separate test function for each of the functions
you’re testing.). Your tests should be based on the function
specifications. Functions are tested by feeding them input and
examining their output. The tests should demonstrate that the
functions work as specified with a variety of inputs.
Requirements:
Your functions should be declared and defined within the
namespace “csutilities”. In order to be compatible
with other languages, define integer as an int using
typedef statement and use integer where you
normally use int for your data types.
Here is a sample run: Don’t worry about
duplicating the same output format for spaces after the
colon.
capitalize("hELLO wORLD"): Hello world
center("C++ is fun"): *****C++ is fun*****
Number of vowles("HEllo WorlD"): 3
lower("hELLO wORLD"): hello world
reverse("Where am I!"): !I ma erehW
hELLO wORLD without vowels is: hll wrld
scrabble_score("FARM"): 9
hELLO wORLD without vowels is: hll wrld
scrabble_score("FARM"): 9
//bitsum.cpp
#include <iostream>
#include <iomanip>
#include <bitset>
using namespace std;
/* Function to get no of set bits in binary
representation of positive integer n */
int numberOfOnes(unsigned long int n)
{
int count = 0;
while (n)
{
/*below code will do logical and of number with 1*/
/*Clearly if corresponding binary bit of unit place = 1
then answer 1 with logical anding else 0*/
count = count + (int)(n & 1);
/*Since we had already evaluated last bit hence discard last bit
by doing binary shift*/
n = n >> 1;
}
return count;
}
/ Program to test function countSetBits /
int main()
{
cout << "Enter number : ";
unsigned long int number;
cin >> number;
cout << left << setw(20) << "Decimal" << setw(32) << "Binary" << " Number of ones" << endl;
cout << left << setw(20) << number << setw(32) << bitset<32>(number) << " " << numberOfOnes(number) << endl;
return 0;
}
C++ help Format any numerical decimal values with 2 digits after the decimal point. Problem descr...
roblem description Write the following functions as prototyped below. Do not alter the function signatures. Demonstrate each function using literal strings defined in your client program (e.g., don't prompt the user for test inputs) /// Returns a copy of the string with its first character capitalized //I and the rest lowercased /// Example: capitalize("hELLO WORLD") returns "Hello world std::string capitalize(const std::string&str) /// Returns a copy of the string centered in a string of length ·width.. /// Padding is done using...
C++ When running my tests for my char constructor the assertion is coming back false and when printing the string garbage is printing that is different everytime but i dont know where it is wrong Requirements: You CANNOT use the C++ standard string or any other libraries for this assignment, except where specified. You must use your ADT string for the later parts of the assignment. using namespace std; is stricly forbiden. As are any global using statements. Name the...
need help on C++ (User-Defined Function) Format all numerical decimal values with 4 digits after the decimal point. Process and sample run: a) Function 1: A void function that uses parameters passed by reference representing the name of a data file to read data from, amount of principal in an investment portfolio, interest rate (any number such as 5.5 for 5.5% interest rate, etc.) , number of times the interest is compounded, and the number of years the money is...
I need help implementing class string functions, any help would be appreciated, also any comments throughout would also be extremely helpful. Time.cpp file - #include "Time.h" #include <new> #include <string> #include <iostream> // The class name is Time. This defines a class for keeping time in hours, minutes, and AM/PM indicator. // You should create 3 private member variables for this class. An integer variable for the hours, // an integer variable for the minutes, and a char variable for...
In C++ please. Thank you!! #include <iostream> #include <cstring> // print an array backwards, where 'first' is the first index // of the array, and 'last' is the last index void writeArrayBackward(const char anArray[], int first, int last) { int i = 0; for (i = last; i >= first; i--) { std::cout << anArray[i]; } std::cout << std::endl; } // test driver int main() { const char *s = "abc123"; writeArrayBackward(s, 0, strlen(s) - 1); } // Using the...
1. Write CppUnitLite tests to verify correct behavior for all the exercises. Using C++ 2. Please show all outputs. Write functions to add one day, another function to add one month, and yet another function to add one year to a Date struct. struct Date { int year; int month; int day; }; Pass Dates by reference when appropriate (i.e., Date& or const Date&). For example, the following function returns by value a new Date instance with one day added...
C++. Need some help getting started. We will also have the following two functions: 1. A mutate function that randomly modifies a chromosome. 2. A crossover function that takes two chromosomes and splits each one at the same spot, then combines them together. Our genetic algorithm works by iterating over generations of chromosomes via the following process: 1. Generate random population. 2. Until we get an answer that is good enough, do the next steps in a loop: (a) Do...
Does any one can show me the code in C++ ll cricket LTE 80% 16:58 Back P2.B MYString v1 Detail Submission Grade For this program, your MYString variables will never need to grow beyond length 20, in program 3 you will need to be allow your string that is held in the class to be able to be larger than 20 chars. So you may want to start allowing your strings to be able to grow....if you have extra time....
Help C++ Write a string class. To avoid conflicts with other similarly named classes, we will call our version MyString. This object is designed to make working with sequences of characters a little more convenient and less error-prone than handling raw c-strings, (although it will be implemented as a c-string behind the scenes). The MyString class will handle constructing strings, reading/printing, and accessing characters. In addition, the MyString object will have the ability to make a full deep-copy of itself...
Hi, it's C++ question. Only can use <iostream> and <fstream>libraries Please help me, thanks Question Description: For this project you will write a program to: a) read-in the 10 first names from a file (the file is a priori given to have exactly 10 entries, of a maximum length of 8 letters each) into a 2-dimensional character array, b) output the names to the terminal with each one preceded by a number indicating its original order in the list, c)...