For this assignment, you will need to create two projects: a) A static library p
ID: 3856311 • Letter: F
Question
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 <string>
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(" ");
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(" ");
return std::string(s, b == std::string::npos ? 0 : b, std::string::npos);
}
std::string trim(const std::string& s) {
const char* ws = " ";
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);
}
}
Explanation / Answer
C# is a modern, general-purpose, object-oriented programming language developed by Microsoft and approved by European Computer Manufacturers Association (ECMA) and International Standards Organization (ISO).
C# was developed by Anders Hejlsberg and his team during the development of .Net Framework.
C# is designed for Common Language Infrastructure (CLI), which consists of the executable code and runtime environment that allows use of various high-level languages on different computer platforms and architectures.
The following reasons make C# a widely used professional language:
Strong Programming Features of C#
Although C# constructs closely follow traditional high-level languages, C and C++ and being an object-oriented programming language. It has strong resemblance with Java, it has numerous strong programming features that make it endearing to a number of programmers worldwide.
Following is the list of few important features of C#:
C# - Environment
In this chapter, we will discuss the tools required for creating C# programming. We have already mentioned that C# is part of .Net framework and is used for writing .Net applications. Therefore, before discussing the available tools for running a C# program, let us understand how C# relates to the .Net framework.
The .Net Framework
The .Net framework is a revolutionary platform that helps you to write the following types of applications:
The .Net framework applications are multi-platform applications. The framework has been designed in such a way that it can be used from any of the following languages: C#, C++, Visual Basic, Jscript, COBOL, etc. All these languages can access the framework as well as communicate with each other.
The .Net framework consists of an enormous library of codes used by the client languages such as C#. Following are some of the components of the .Net framework:
For the jobs each of these components perform, please see ASP.Net - Introduction, and for details of each component, please consult Microsoft's documentation.
Integrated Development Environment (IDE) for C#
Microsoft provides the following development tools for C# programming:
The last two are freely available from Microsoft official website. Using these tools, you can write all kinds of C# programs from simple command-line applications to more complex applications. You can also write C# source code files using a basic text editor, like Notepad, and compile the code into assemblies using the command-line compiler, which is again a part of the .NET Framework.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.