Computer Programming Assignment Help

Introduction

This is an introductory assignment, designed to get you used to working with the C programming language and the Git repository.

It is assumed that the student is already familiar with computer programming. The student is expected to produce quality code. The code should be properly formatted and properly commented. Marks will be deducted if this is not the case.

The issue of plagiarism is taken seriously in this course. USQ policies on plagiarism may be found  .The assignment will be marked out of 40. This assignment is worth 10% of the marks for the course.

 

Topics Covered in this assignment

 
  • The use of the Git repository.

  • The use of a makefil

  • C programming:-

  • C command line argument

  • Using pointers in C

  • Calling functions in C

  • Writing functions in C

  • Reading from and writing to fil

  • Encapsulation in C.

  • Aspects of a typical server

  • configuration

  • logging


 

 

The use of the Git repository.

2-19

In this course, you are provided with a Git repository. Your marker will access your Git repository. You may have already used Git for other subjects at this university, but for those not already familiar with Git, please use the following links to make yourself familiar with Git and with revision control systems in general.

 
  • Revision control system

  • Chapter 2 (Git basics) of the book Pro Git.


 

You are required to commit to the Git repository as you develop the code. It will not be acceptable to submit your code to the repository only as the assignment due date approaches. The marker will us Git to see the development history of the source code. It will be hard to convince the marker that the work is

your own work unless the marker can see the progress of development leading to your solution at the time of marking.

You are expected to organise your work in a logical and consistent manner. Marks will be deducted if the required parts of your work is difficult to find. When you initially check out your Git repository, there should be a directory (folder) in your Git space called "Ass0". For questions that involve writing computer programs, you should find code that you need to use for the question and a makefile on the study desk. Also you need to check your work in there.

You should check in source code such as ".c" file and ".h" files into the Git repository. You should also check in any documentation files into the Git repository. You should not, however, check in any of the files that were created by the compiler, such as ".o" files or the resulting executable file.

Marking Platform

 

For the sake of efficiency, your marker will inspect, compile and run on the Linux operating system as provided for this course. The marker will go to the directory associated with the question and inspect the code. He or she will type the command "make" in order to compile the program. Hopefully, the program should compile without errors. The marker will then test the program. Although some marks may well be awarded for work done, a program needs to compile and run without errors in order to get full marks.

 

Indent Style

 

Your code should be indented using  Allman / Horstmann style coding styles. Other indent styles are not acceptable.

Question 1: Reading and writing from files one line at a time.                                        Out of 10 marks.

Topics Covered in this question
  • Command line arguments in

  • Opening a file for read.

  • Opening a file for writ

  • Looping

  • Reading a line at a time from a stream.

  • Writing to a stream.


 

Background

Many network protocols, such as HTTP, use a line based approach to issuing commands and receiving responses. Here we will practice reading one line at a time.

Your task

Create a program called "enquote" that takes two arguments from the command line. The first argument will be the name or path of the input file, (i.e. a file to read from) and the second argument output file (i.e. a file to write to). Your program will read each line from the input file and write it to the output file with each line presented in quotation marks. E.g. If the input file contains the text :-

The quick brown fox jumped over the lazy dogs tail

Then after running your program the output file will contain.

"The quick brown" "fox jumped over" "the lazy dogs tail"

Your program must not crash under any circumstance. For example, if the marker provides an input file that has the entire old testament in a single line, it would be acceptable for that line to be truncated, but would not be acceptable for program to crash as a result.

 

Your program should use the following algorithm:-

 

*                 if the  number of  arguments is  not 2, then

*                 Give an error  message and quit with return error  code.

 

*                 Try to  open the  first file for input

*                 On  failure

*                 Give an error  message and quit with return error  code.

 

*                 Try to  open the  second file for output

*                 On  failure

*                 Give an error  message and quit with return error  code.

 

*                 Loop

 

*                 Try to read in a line

*                 On  failure

*                 Exit the loop.

*                 Write the line  in quotes

*                 Close the input file.

*                 Close the  output file.

*                 Return success.

The function fgetline() is provided for you. The documentation for the function may be found in the header file "fgetline.h". You may choose to use it or not.

Did you notice?

You used a set of library routines to perform all of your file handling. These routines were all declared in the header file which you #included.

You opened your files using a call to fopen(), which on success, returned a file handle (of type "FILE*"). fopen() is analogous to a constructor in object oriented programming.

 

You then had access to various routines, all of which used the file handle, such as fprintf(), fgetc(), fread(), fwrite() etc, and also fgetline(). These are analogous to methods in object oriented programming.

Finally, you used fclose() to release resources associated with the open file. This is analogous to a destructor in object oriented programming.

 

The type "FILE" is analogous to a class in object oriented programming and the file handle returned is analogous to an object. The interface is provided, but the implementation details are hidden. In fact, you could totally rewrite the implementation, so long as the interface does not change. This happens all the

 

time, for example, when you use the same programming interface on a different operating system or different compiler.

Object oriented programming uses:-

 
  • Encapsulation, which is far and away the most important aspect. This is closely related to Data Abstraction and Data Hidi

  • Inheritance

  • and Polymorphism.


The file handling library that you used provided encapsulation, data abstraction and data hiding but it was not truly object oriented because it did not provide inheritance or polymorphism.

 

Question 2                                                                                                                              Out of 10 marks.

Topics Covered in this question
  • Server configuration

Background

A word processor, like most GUI programs, takes its instructions from its graphical user interface. Many command line programs get all of the information that they need from command line. In contrast, a server generally cannot, for the following reasons:-

 
  • A server is generally meant to be activated as soon as the computer boots. Therefore it has no interface to a user. If follows that that a server may have no connection to a command line or a graphical user interface.

  • Server machines are generally not desktop machines. They often do not have a graphical user interface or a command line. This keeps them small so that the operating system can be minimal, which is good for operating a server in a virtual machine..

  • There are often far too many variables to get, and giving instructions via a command line tends to become too complicated.


 

It is normal practice, therefore, for a server to get its parameters, called configuration, from a configuration file.

 

Some popular candidates for server configuration are as follows:-

 
  • Windows registry. While Microsoft encourages this option, it is for Microsoft Windows only. It is therefore not ideal for cross platform development.

  • Unix and Linux configurations tend to be ad hoc. There have been attempts to standardise them but these have often not been successful.

  • Multi level configurations may well choose XML for configuration. It is multi-level and extensible. XML is an industrial strength configuration option suitable for large configuration files.

  • Ini file style configuration is popular. It is easily the simplest, yet can handle serious configurations. It is used on every operating system.


 

Further reading: The Poco library, which is a library oriented around network programming, features an industrial strength configuration library.  Poco Configuration libraries

 

Your Task

 

Create a program called "server" that takes one argument, the path of its Ini style configuration file similar to the one provide here. Your program, called "server" will not be a true server, but will merely print the values of "path" and "logLevel" which may both be found in the "Logging" section of the provided ini file, "test.ini".

 

Your code should go into the file "server.c".

 

The basic ini-file configuration library (iniFile.h and iniFile.c) is provided for you to use. Carefully read the documentation that is provided in "iniFile.h". Ask questions in the forums if you do not understand or you find errors in the documentation.

 

One thing that you should look out for, in the documentation is freeing any allocated strings. You would lose marks if you fail to release this memory, or fail to release the configuration object before main() returns. Ask about this in the forums if you do not understand.

Also, be sure that your program checks the return values and prints an error message if something is wrong, e.g. What happens if the configuration file is missing?

Did you notice?

You used a set of library routines to obtain your server configuration. These routines were all declared in the header file "iniFile.h" which you included. The header file that you included gave no details about its implementation.

You opened your files using a call to iniFile_new(), which returned a handle. iniFile_new() is analogous to a constructor in object oriented programming.

You then had access to other routines, and the names of these routines all began with "iniFile_".

Finally, you used iniFile_close() to release resources. This is analogous to a destructor in object oriented programming.

The iniFile library that you used provided encapsulation, but it was not truly object oriented because it did not provide inheritance or polymorphism.

Question 3                                                                                                                              Out of 10 marks.

Topics Covered in this question
  • Server logging

Background

1-19

Servers are generally detached from any command line interface, and have no graphical user interface. So, if anything goes wrong, where do the error messages go? On Linux they usually go into some file in the directory /var/log. So if you had a problem with your server, that is where you should look in order to find out what went wrong.

When a server starts up or shuts down, it makes an entry in its log file. When there is an error, or something interesting, such as a failed authorisation, it puts that in the log file too.

Entries are mostly one per line, but multi-line entries occur if an entry would be too long.

Each entry in the log file is accompanied by a time and date. This may help in matching up an incident with a log entry.

One common feature of logging libraries is that of the logging level. The logging library is told the current logging level as part of its initialisation. This would generally come from the configuration. Each call to log a message comes with the urgency of the message. The message is only sent to the logging file if the urgency of the message is greater or equal to the current logging level.

 

Another common feature of logging libraries is that of changing log files and compressing old log files. Server logging libraries can be quite extensive, but a very simple one can also be quite effective.

Further reading:  The Poco library, which is a library oriented around network programming, features an industrial strength logging library.

Your Task

Your task is to demonstrate basic server logging.

Your code should use the configuration as per question 2. It should obtain the path of the logging file and the logging level from the configuration library and write some logging entries to the logging file.

 

Every time you log a message a new entry should be appended to the log file. The entry should consist of the date and time followed by the logged message.

Your code should go into the file "server.c".

The basic logging library "logger.c" is provided for you to use. "server.c" needs to #include the file "logger.h" in the same way that you #included "iniFile.h". Carefully read the documentation that is provided in "logger.h". Ask questions in the forums if you do not understand or you find errors in the documentation.

As in question 2, you would lose marks if you fail to release memory, or fail to release the configuration object before main() returns. Also as in Question 2, be sure that your program checks the return values and prints an error message if something is wrong.

The provided configuration file gives a logging path to somewhere in the "/var/log" directory that normal users do not have permission to access. You will need to change that logging path to a directory where you do have permission to create files. For a real server, an absolute path would be suitable. For the purpose of this assignment, please use the relative path, "server.log".

Your program should demonstrate two logging entries at the TRACE level and one at the ERROR level.

Question 4                                                                                                                  Out of 10 marks.

Question 4 is a report, requiring some research on your behalf. The report should be in the form of a PDF document. It should be a properly formatted document, complete with:-
  • A title page that has:-

  • Your name

  • Your student number

  • The date

  • The course code

  • The assignment number

  • The question number

  • A table of contents

  • Headings and Sub-Headings


The title page should be followed with one or two pages containing parts A, B and C.

Part A) Object Oriented Programming

Explain the principles of object oriented programming in three paragraphs or more.

Part B) Server Configuration

Explain at least 3 different approaches to server configuration. Give advantages and disadvantages of each approach.

This is an open ended question. You can limit your discussion to file formats, if you like, or you may address wider issues.

Part C) Logging
  1. What is the purpose of logging levels?

  2. Explain log rotation as it applies to logging.

  3. Contact us at hndassignmenthelp@gmail.com

Comments