100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
main.c code $33.67   Add to cart

Other

main.c code

 24 views  1 purchase
  • Course
  • Institution

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%: Loo...

[Show more]

Preview 3 out of 24  pages

  • February 24, 2023
  • 24
  • 2022/2023
  • Other
  • Unknown
  • Unknown
avatar-seller
// 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");

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller kaloyantitov. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $33.67. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

80202 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$33.67  1x  sold
  • (0)
  Add to cart