Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this assignment, you will need to create two projects: a) A static library project. b) A console application that will link in the library

For this assignment, you will need to create two projects: a) A static library project. b) A console application that will link in the library from (1.a).

2) In the library project, place the files attached to this assignment: trim.h trim.cpp Compile this project to make sure that it produces a library (.lib file) and note the directory where it places the library. Also, note the directory where the source files reside (to know where the .h is). You will need these two directories to fill out the project settings in the application.

3) Create a separate console application project that will contain your code that will use the library. Make all the project settings necessary to point to the correct locations for both the preprocessor and the linker (for the header file(s) and library, respectively)

4) In the console application project, create an account.h (and account.cpp if necessary) to implement a class, account. An account needs to hold the following: std::string account code; std::string first_name; std::string last_name; double balance; Provide all necessary constructors, accessors, and operators.

5) Create a main.cpp in the console application project and include the account.h header (from your library project) in addition to and any other standard headers you will need (i.e and ).

6) In the main function: a) Create a std::vector of accounts. b) Open a std::ifstream on the file account.dat, which is in the following line-oriented, fixedcolumn width format: account_code: 10 characters first_name: 15 characters last_name: 25 characters balance: 8 digits, decimal place, 2 digits c) In a loop, read each account, which is on a separate line (delimited with ). The recommendation is to read each line as a std::string (e.g. with std::getline) and perform substrings to get the individual pieces of information. There are other possible implementations. If there are any errors either accessing the file or in the data format, throw an appropriate exception. Make sure you check for lines that are not the correct size (esp. too short)!! Note - because each field is fixed-width, the first and last names can and will have blanks on the end. Use the trim or trim_right function (from the library) to remove the spaces from the names. d) For each account read from the file, store it in the vector created in (6.a). e) Output the vector of accounts to a file, account.csv, using a std::ofstream in comma-delimited format. For instance, 1234567890Fred Murtz 00002000.01 in the fixed-length file becomes 1234567890,Fred,Murtz,2000.01

7) For all exceptions, make sure an error message detailing the cause of the exception outputs to the console before exiting the program. Any further information (i.e. file and line number of exception) is purely optional.

8) For ten bonus points, use std::sort to sort the accounts by account number before writing them to the CSV file.

trim.h

#pragma once

#if !defined(__generic_trim_h__) #define __generic_trim_h__

#include

namespace generic {

std::string trim_right(const std::string& s); std::string trim_left(const std::string& s); std::string trim(const std::string& s);

}

#endif

trim.cpp

#include "trim.h"

namespace generic {

std::string trim_right(const std::string& s) {

std::string::size_type e = s.find_last_not_of(" \t \f");

return std::string(s, 0, e == std::string::npos ? 0 : e + 1);

}

std::string trim_left(const std::string& s) {

std::string::size_type b = s.find_first_not_of(" \t \f");

return std::string(s, b == std::string::npos ? 0 : b, std::string::npos);

}

std::string trim(const std::string& s) {

const char* ws = " \t \f";

std::string::size_type e = s.find_last_not_of(ws);

std::string::size_type b = s.find_first_not_of(ws);

if (b == std::string::npos) { b = 0; }

return std::string(s, b, e == std::string::npos ? 0 : e - b + 1);

}

}

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

The Manga Guide To Databases

Authors: Mana Takahashi, Shoko Azuma, Co Ltd Trend

1st Edition

1593271905, 978-1593271909

More Books

Students also viewed these Databases questions

Question

apply research strategies to writing.

Answered: 1 week ago