Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For this assignment, you will need to create two projects: a) A static library p

ID: 3856312 • 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

When this code is compiled and executed, it produces the following result:

Let us look at the various parts of the given program:

The first line of the program using System; - the using keyword is used to include the System namespace in the program. A program generally has multiple using statements.

The next line has the namespace declaration. A namespace is a collection of classes. The HelloWorldApplication namespace contains the class HelloWorld.

The next line has a class declaration, the class HelloWorld contains the data and method definitions that your program uses. Classes generally contain multiple methods. Methods define the behavior of the class. However, the HelloWorld class has only one method Main.

The next line defines the Main method, which is the entry point for all C# programs. The Main method states what the class does when executed.

The next line /*...*/ is ignored by the compiler and it is put to addcomments in the program.

The Main method specifies its behavior with the statement Console.WriteLine("Hello World");

WriteLine is a method of the Console class defined in the Systemnamespace. This statement causes the message "Hello, World!" to be displayed on the screen.

The last line Console.ReadKey(); is for the VS.NET Users. This makes the program wait for a key press and it prevents the screen from running and closing quickly when the program is launched from Visual Studio .NET.

It is worth to note the following points:

C# is case sensitive.

All statements and expression must end with a semicolon (;).

The program execution starts at the Main method.

Unlike Java, program file name could be different from the class name.

Compiling and Executing the Program

If you are using Visual Studio.Net for compiling and executing C# programs, take the following steps:

Start Visual Studio.

On the menu bar, choose File -> New -> Project.

Choose Visual C# from templates, and then choose Windows.

Choose Console Application.

Specify a name for your project and click OK button.

This creates a new project in Solution Explorer.

Write code in the Code Editor.

Click the Run button or press F5 key to execute the project. A Command Prompt window appears that contains the line Hello World.

You can compile a C# program by using the command-line instead of the Visual Studio IDE:

Open a text editor and add the above-mentioned code.

Save the file as helloworld.cs

Open the command prompt tool and go to the directory where you saved the file.

Type csc helloworld.cs and press enter to compile your code.

If there are no errors in your code, the command prompt takes you to the next line and generates helloworld.exe executable file.

Type helloworld to execute your pr

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote