Garantie de satisfaction à 100% Disponible immédiatement après paiement En ligne et en PDF Tu n'es attaché à rien
logo-home
main.c code €31,29   Ajouter au panier

Autre

main.c code

 23 vues  1 achat
  • Cours
  • Établissement

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...

[Montrer plus]

Aperçu 3 sur 24  pages

  • 24 février 2023
  • 24
  • 2022/2023
  • Autre
  • Inconnu
  • Inconnu
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");

Les avantages d'acheter des résumés chez Stuvia:

Qualité garantie par les avis des clients

Qualité garantie par les avis des clients

Les clients de Stuvia ont évalués plus de 700 000 résumés. C'est comme ça que vous savez que vous achetez les meilleurs documents.

L’achat facile et rapide

L’achat facile et rapide

Vous pouvez payer rapidement avec iDeal, carte de crédit ou Stuvia-crédit pour les résumés. Il n'y a pas d'adhésion nécessaire.

Focus sur l’essentiel

Focus sur l’essentiel

Vos camarades écrivent eux-mêmes les notes d’étude, c’est pourquoi les documents sont toujours fiables et à jour. Cela garantit que vous arrivez rapidement au coeur du matériel.

Foire aux questions

Qu'est-ce que j'obtiens en achetant ce document ?

Vous obtenez un PDF, disponible immédiatement après votre achat. Le document acheté est accessible à tout moment, n'importe où et indéfiniment via votre profil.

Garantie de remboursement : comment ça marche ?

Notre garantie de satisfaction garantit que vous trouverez toujours un document d'étude qui vous convient. Vous remplissez un formulaire et notre équipe du service client s'occupe du reste.

Auprès de qui est-ce que j'achète ce résumé ?

Stuvia est une place de marché. Alors, vous n'achetez donc pas ce document chez nous, mais auprès du vendeur kaloyantitov. Stuvia facilite les paiements au vendeur.

Est-ce que j'aurai un abonnement?

Non, vous n'achetez ce résumé que pour €31,29. Vous n'êtes lié à rien après votre achat.

Peut-on faire confiance à Stuvia ?

4.6 étoiles sur Google & Trustpilot (+1000 avis)

73314 résumés ont été vendus ces 30 derniers jours

Fondée en 2010, la référence pour acheter des résumés depuis déjà 14 ans

Commencez à vendre!
€31,29  1x  vendu
  • (0)
  Ajouter