100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Other

main.c code

Rating
-
Sold
1
Pages
24
Uploaded on
24-02-2023
Written in
2022/2023

main.c is made of different functions and arrays. It must be executed with the headers files, (colours.h) and (global_variables.h) The Car Sales project must make its output to the Console (i.e. the Command Prompt using printf) and it must exhibit the following features as a minimum: 5%: Looping Menu with 3 main actions: View Cars Stock, Buy Cars, View Sales Data Note: A Car is defined by its price and model 5%: Must contain at least three arrays to cars information (maximum of 10 Car models) Two for recording the price and name of a car One for recording the remaining amount of each car model 5%: View Cars Stock will show a list of models and remaining amount 4%: Sorted by remaining amount in descending order 10%: Buying Cars needs to record the total price/customer name/customer age/if discount was given/discount value/number of cars and update existing car arrays as necessary once a sale is concluded 4%: Any data being accepted from the keyboard needs to be validated and filtered (i.e. only accept correct data from the customer and keep asking until correct data is entered) 10%: Sales Data for a Car Model is also displayed as a total sum for each model, in addition to displaying what each customer bought 10%: Sorted by total sale amount in descending order 10%: Sales Data is to be stored in a file 10%: When the program launches, it should read previous sales data from the file, if it exists, to be used as initial data 2%: Exiting the software thanks the customer for using it before closing 15%: Make use of topics not taught in the module, but can be applied in a relevant way to this software project (do not include features/topics just for the sake of showing that you know how to use/implement it, instead consider why it will improve the software for the user) - e.g. struct 5%: Your code needs to follow recommended coding standards and good practice (see Week 2) 5%: Also submit a Logbook detailing your engagement with the Pluralsight platform, including your Pluralsight C exam (test) results. Please see this page for information on this. Total: 100% Note: Please do not feel like you need to limit yourselves to the above features list. I'm happy for you to explore adding in other features beyond the ones listed above (but as a minimum the program must exhibit the listed features). The marks are awarded based on the complexity of each feature, as the case may be. For example, having a Looping Menu that does not validate user input (i.e. it blindly trusts the keyboard input), but works well for its intended purpose is worth 2%, while also validating the user's choice (i.e. did they type an expected character that's part of the menu? - switch does not count for this purpose) before it is fully accepted would attract 4-5% (assuming the code works as intended with no issues), depending on the technical quality of the work. A similar approach will be taken when marking the entire project.

Show more Read less
Institution
Course










Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
Study
Unknown
Course

Document information

Uploaded on
February 24, 2023
Number of pages
24
Written in
2022/2023
Type
Other
Person
Unknown

Subjects

Content preview

// https://github.com/kaloyannt
//THIS PROJECT IS LISTED ON MY GITHUB PROFILE

//We are using _CRT_SECURE_NO_WARNINGS in order to be able to use (scanf)
#define _CRT_SECURE_NO_WARNINGS
SetConsoleOutputCP(CP_UTF8);

#include <stdio.h> //<--- External headers
#include <stdlib.h> //<--- External headers
#include <string.h> //<--- External headers
#include <conio.h> //<--- External headers

/*Colours will be used to enhnance the user experience
and provide guidance. For example Green (Success); Red
(Error); Yellow (Information) .. https://www.theurbanpenguin.com/4184-2/ */
#include "colours.h" // <--- This is my own header, located as a seperate file.

//This is the header, where I store all my global variables that I need access
anywhere
//In the program.
#include "global_variables.h" //<--- This is my own header, located as a seperate
file.

void files() {
//NAMING THE FILES POINTERS
FILE* sales_data; FILE* payment_details;

//OPENING THE FILES
//WE HAVE TO OPEN THE FILES WAY BEFORE THE PROGRAM BEGINS, TO ENSURE THAT
//WHEN THE SALES PAGE IS OPEN, THE PROGRAM DOES NOT CRASH
//THE PROGRAM WILL LOOK FOR THOSE FILES AND IF THEY DO NOT EXIST, IT WILL
THROW AN ERROR.
//Source: https://www.guru99.com/c-file-input-output.html
//"append mode. If a file is in append mode, then the file is opened. The
content within the file doesn’t change."
sales_data = fopen("sales_data.txt", "a"); payment_details =
fopen("payment_details.txt", "a");
fclose(sales_data); fclose(payment_details);
}

//Pauses the program function
void pause_program() {
char pause;
scanf("\n%hd\n", &pause);
}

//Clear program screen function
void clearScreen() {
system("cls");
}

//Allows user to return to the main menu
void back_to_menu() {
printf("Enter (y) to return to the menu -- (n) to exit the program.\n");
char backinput;
//Filter user Input
//This is used at the end of every purchase, to allow the user to return to the
menu.
fscanf(stdin, "\n%c", &backinput);

, if (backinput == 'y') {
//If their input is equal to y, execute the function below
//Take user back to the main menu.
main();
clearScreen();
}
//If their input is equal to n, execute the code below:
else if (backinput == 'n') {
exit(1);
}
//If their input is not matching n or y, then execute the code below:
else {
printf("Sorry, invalid option");
}
}

//Main main, present user with 3 options to choose from.
int show_menu() {
reset();
clearScreen();
printf(":----------------------------------:\n");
yellow();
printf(": M A I N M E N U :\n");
reset();
printf(":----------------------------------:\n");
printf(":----------------------------------:\n");
printf(": Please select an option :\n");
printf(": 1. Buy Cars :\n");
printf(": 2. View sales Data :\n");
printf(": 3. View Cars Stock :\n");
printf(": 4. Admin :\n");
printf(":----------------------------------:\n");
printf(": Welcome to MOD003212 Car Sales :\n");
green();
printf(": Software author: Kaloyan Titov :\n");
reset();
printf(": Local time @%s :\n", __TIME__);
cyan();
printf(": https://github.com/kaloyannt :\n");
reset();
printf(":----------------------------------:\n");

//\n (new line) in order to ignore my previous input of y or n and allow me
to enter a new input.
printf("Option /> "); scanf("\n%c", &menu_option);
}

//Show cars Available
//This function, will be used to reset and set the stock,
//Every time when the program is closed and re-opened.
int carsAvailable() {

//Naming the file
FILE* carsAvailable;
//Creating the file, before the program executes.
carsAvailable = fopen("carsAvailable.txt", "w");

//Writing the amount of cars declared to the file.
fprintf(carsAvailable, "%d", setCarStock); // <-- This variable contains the

, amount of stock to write to the file.
// The setCarStock variable is stored in global_variables.h file.

//Closing the file
fclose(carsAvailable);

//Opening the file again, but to read this time.
carsAvailable = fopen("carsAvailable.txt", "r");

//Creating a new int variable named scanCarsAvailable, to scan the contents
of the file and put them
//Into the variable named cars
unsigned long cars;
int scanCarsAvailable = fscanf(carsAvailable, "%d", &cars);

//If variable cars (which contains the number from the file) is more than 0
//Run the code below:
if (cars > 0) {
printf("%d", cars);
}
//If is less than 0, then display that there is no more stock;
else {
printf("No more cars available");
}
//Close the file again
fclose(carsAvailable);
}

//This would update the GLOBAL stock, once any purchase has been made.
int updatedGlobalStock() {
//Updating the global car stock, when a car model is purchased.
//This is a arithmetic calculation that will updated the stock
//Accordingly, depending on how many cars have been brought for each brand.
//The stock will be updated globally in the program.
setCarStock -= carsNeededMercedes;
setCarStock -= carsNeededAudi;
setCarStock -= carsNeededToyota;
setCarStock -= carsNeededPorsche;
setCarStock -= carsNeededBmw;
}

/*This is the purchase screen that the user is presented with, once
They have selected the model number "101" */
int purchaseScreenMercedes() {


//NAMING THE FILES POINTERS
FILE* sales_data; FILE* payment_details;

//OPENING THE FILES
//WE HAVE TO OPEN THE FILES WAY BEFORE THE PROGRAM BEGINS, TO ENSURE THAT
//WHEN THE SALES PAGE IS OPEN, THE PROGRAM DOES NOT CRASH
//THE PROGRAM WILL LOOK FOR THOSE FILES AND IF THEY DO NOT EXIST, IT WILL
THROW AN ERROR.
//Source: https://www.guru99.com/c-file-input-output.html
//"append mode. If a file is in append mode, then the file is opened. The
content within the file doesn’t change."
sales_data = fopen("sales_data.txt", "a"); payment_details =
fopen("payment_details.txt", "a");
$34.95
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached


Document also available in package deal

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
kaloyantitov Norwich City College of Further and Higher Education
Follow You need to be logged in order to follow users or courses
Sold
84
Member since
3 year
Number of followers
69
Documents
14
Last sold
5 months ago
Level 2, Level 3, 3 Extended Assignments - Information and Technology.

Please note, all assignments listed on my profile are completed to a distinction standard, they have been marked and graded by teachers. Please send me a message if more information is needed or if something is unclear. Kind Regards

2.8

19 reviews

5
6
4
2
3
1
2
2
1
8

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their exams and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can immediately select a different document that better matches what you need.

Pay how you prefer, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card or EFT and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions