URGENT

Joined
Jan 31, 2023
Messages
1
Reaction score
0
Hi, I'm having problems with an assignment, could someone help me?
Task: Create software that simulates tracking the movement of a moving stretcher or elevator. We know that we have this type of software, and by creating it, you will go through a series of elements that we covered during the winter semester. Initially, through the project, you will test your personal programming logic, then the method of setting up and creating the project, as well as the method of collecting, printing and presenting data to end users.
For the purposes of the project, we initially have to create two sides, the user side and the admin side, after that we need to create options through which we can set the commands that we will list in the rest of the text, which will represent the structure and our basic functionality.
The basic functionality of the program would be that the admin can specify the size of the object and the number of stretcher movements before servicing, we also need to have an option to monitor the current number of movements as well as print out the elevators that are in the queue for servicing. While the user side has access to activate the stretcher, and during the activation we need to graphically simulate the movement of an object through the terminal, this of course depends on the data created by the admin, which refers to the number of floors and the number of movements.I have an error and I can't print the user part.

#include <stdio.h>
#include <string.h>

#define MAX_USERS 10
#define MAX_NAME_LENGTH 30
#define MAX_EMAIL_LENGTH 50
#define MAX_PASSWORD_LENGTH 20


struct Admin {
char email[MAX_EMAIL_LENGTH];
char password[MAX_PASSWORD_LENGTH];

} admin;



int main() {
// Učitavanje admin podataka iz fajla "admin.dat"
FILE *fp = fopen("admin.dat", "r");
if(fp==NULL){
printf("Ne postoji fajl admin.dat, molimo vas da ga napravite\n");
return 0;
}
fread(&admin, sizeof(admin), 1, fp);
fclose(fp);

char email[MAX_EMAIL_LENGTH], password[MAX_PASSWORD_LENGTH];
printf("Unesite email: ");
scanf("%s", email);
printf("Unesite lozinku: ");
scanf("%s", password);

// Provjera da li su uneseni podaci ispravni
if (strcmp(email, "(e-mail address removed)") == 0 && strcmp(password, "admin") == 0) {
printf("Ulogovani ste kao admin.\n");

int choice;
do {
printf("Admin opcije:\n");
printf("1. Kreiranje novog korisnika\n");
printf("2. Kreiranje novog nosila\n");
printf("3. Trenutni broj koristenja nosila\n");
printf("4. Nosila spremna za servisiranje\n");
printf("5. Blokirana nosila\n");
printf("6. Exit\n");
printf("Izbor: ");
scanf("%d", &choice);

switch (choice) {

case 1:
// Kreiranje novog korisnika
char newEmail[MAX_EMAIL_LENGTH], newPassword[MAX_PASSWORD_LENGTH];
printf("Unesite novi email: ");
scanf("%s", newEmail);
printf("Unesite novu lozinku: ");
scanf("%s", newPassword);

// Snimanje novog korisnika u fajl "admin.dat"
fp = fopen("admin.dat", "w");
if(fp==NULL){
printf("Ne postoji fajl admin.dat, molimo vas da ga napravite\n");
return 0;
}
strcpy(admin.email, newEmail);
strcpy(admin.password, newPassword);
fwrite(&admin, sizeof(admin), 1, fp);
fclose(fp);
printf("Korisnik uspjesno kreiran.\n");
break;

case 2:
// Kreiranje novog nosila
struct Nosilo {
char ime[256];
int sprat;
int korisnik;
int servis;
} nosilo;

printf("Unesite naziv nosila: ");
scanf("%s", nosilo.ime);
printf("Unesite broj spratova gdje se nosilo koristi: ");
scanf("%d", &nosilo.sprat);
printf("Unesite koliko puta se nosilo moze aktivirati prije servisa: ");
scanf("%d", &nosilo.korisnik);
printf("Unesite broj koji se dodaje na broj koristenja kada se oznaci za servis: ");
scanf("%d", &nosilo.servis);

// Snimanje novog nosila u fajl "nosila.dat"
fp = fopen("nosila.dat", "a");
if(fp==NULL){
printf("Ne postoji fajl nosila.dat, molimo vas da ga napravite\n");
return 0;
}
fwrite(&nosilo, sizeof(nosilo), 1, fp);
fclose(fp);
printf("Nosilo uspjesno kreirano.\n");
break;

case 3:

// Trenutni broj korištenja nosila
char naziv_nosila[256];
printf("Unesite naziv nosila: ");
scanf("%s", naziv_nosila);
struct koristenje_nosilo {
char ime[256];
int trenutno_koristenja;
int sprat;
int korisnik;
int servis;
} koristenje_nosilo;

// Citanje nosila iz fajla "nosila.dat"
fp = fopen("nosila.dat", "r");
if(fp==NULL){
printf("Ne postoji fajl nosila.dat, molimo vas da ga napravite\n");
return 0;
}
while(fread(&nosilo, sizeof(nosilo), 1, fp)){
if(strcmp(nosilo.ime, naziv_nosila) == 0){
printf("Naziv nosila: %s\n", nosilo.ime);
printf("Trenutno koristenja: %d\n", koristenje_nosilo.trenutno_koristenja);
printf("Razlika izmedu trenutnog stanja i servisiranja/blokiranja: %d\n", koristenje_nosilo.korisnik - koristenje_nosilo.trenutno_koristenja + koristenje_nosilo.servis);
break;
}
}
fclose(fp);
break;

case 4:
//Nosila spremna za servis

int servisiranje[20];

// Inicijaliziraj niz na 0
for (int i = 0; i < 20; i++)
servisiranje = 0;

// Prikaz nosila koja su ispunila zadati broj
for (int i = 0; i < 20; i++) {
if (servisiranje == 1)
printf("Naziv nosila: %d\n", i);
}
// Funkcija za resetiranje nosila i
// postavljanje niza na 0
void resetNosila()
{
for (int i = 0; i < 20; i++)
servisiranje = 0;
}

case 5:
// Blokirana nosila
printf("Blokirana nosila\n");
int blokiranje[20];

// Inicijaliziraj niz na 0
for (int i = 0; i < 20; i++)
blokiranje = 0;

// Prikaz nosila koja su ispunila zadati broj
for (int i = 0; i < 20; i++) {
if (blokiranje == 1)
printf("Naziv nosila: %d\n", i);
}
case 6:
printf("Izlaz iz programa\n");
break;
default:
printf("Pogresan izbor\n");
break;
}
} while (choice != 6);
} else {
printf("Unijeli ste pogresne podatke.\n");
}
}
 
Joined
Jan 30, 2023
Messages
107
Reaction score
13
Hi, I'm having problems with an assignment, could someone help me?
Task: Create software that simulates tracking the movement of a moving stretcher or elevator. We know that we have this type of software, and by creating it, you will go through a series of elements that we covered during the winter semester. Initially, through the project, you will test your personal programming logic, then the method of setting up and creating the project, as well as the method of collecting, printing and presenting data to end users.
For the purposes of the project, we initially have to create two sides, the user side and the admin side, after that we need to create options through which we can set the commands that we will list in the rest of the text, which will represent the structure and our basic functionality.
The basic functionality of the program would be that the admin can specify the size of the object and the number of stretcher movements before servicing, we also need to have an option to monitor the current number of movements as well as print out the elevators that are in the queue for servicing. While the user side has access to activate the stretcher, and during the activation we need to graphically simulate the movement of an object through the terminal, this of course depends on the data created by the admin, which refers to the number of floors and the number of movements.I have an error and I can't print the user part.

#include <stdio.h>
#include <string.h>

#define MAX_USERS 10
#define MAX_NAME_LENGTH 30
#define MAX_EMAIL_LENGTH 50
#define MAX_PASSWORD_LENGTH 20


struct Admin {
char email[MAX_EMAIL_LENGTH];
char password[MAX_PASSWORD_LENGTH];

} admin;



int main() {
// Učitavanje admin podataka iz fajla "admin.dat"
FILE *fp = fopen("admin.dat", "r");
if(fp==NULL){
printf("Ne postoji fajl admin.dat, molimo vas da ga napravite\n");
return 0;
}
fread(&admin, sizeof(admin), 1, fp);
fclose(fp);

char email[MAX_EMAIL_LENGTH], password[MAX_PASSWORD_LENGTH];
printf("Unesite email: ");
scanf("%s", email);
printf("Unesite lozinku: ");
scanf("%s", password);

// Provjera da li su uneseni podaci ispravni
if (strcmp(email, "(e-mail address removed)") == 0 && strcmp(password, "admin") == 0) {
printf("Ulogovani ste kao admin.\n");

int choice;
do {
printf("Admin opcije:\n");
printf("1. Kreiranje novog korisnika\n");
printf("2. Kreiranje novog nosila\n");
printf("3. Trenutni broj koristenja nosila\n");
printf("4. Nosila spremna za servisiranje\n");
printf("5. Blokirana nosila\n");
printf("6. Exit\n");
printf("Izbor: ");
scanf("%d", &choice);

switch (choice) {

case 1:
// Kreiranje novog korisnika
char newEmail[MAX_EMAIL_LENGTH], newPassword[MAX_PASSWORD_LENGTH];
printf("Unesite novi email: ");
scanf("%s", newEmail);
printf("Unesite novu lozinku: ");
scanf("%s", newPassword);

// Snimanje novog korisnika u fajl "admin.dat"
fp = fopen("admin.dat", "w");
if(fp==NULL){
printf("Ne postoji fajl admin.dat, molimo vas da ga napravite\n");
return 0;
}
strcpy(admin.email, newEmail);
strcpy(admin.password, newPassword);
fwrite(&admin, sizeof(admin), 1, fp);
fclose(fp);
printf("Korisnik uspjesno kreiran.\n");
break;

case 2:
// Kreiranje novog nosila
struct Nosilo {
char ime[256];
int sprat;
int korisnik;
int servis;
} nosilo;

printf("Unesite naziv nosila: ");
scanf("%s", nosilo.ime);
printf("Unesite broj spratova gdje se nosilo koristi: ");
scanf("%d", &nosilo.sprat);
printf("Unesite koliko puta se nosilo moze aktivirati prije servisa: ");
scanf("%d", &nosilo.korisnik);
printf("Unesite broj koji se dodaje na broj koristenja kada se oznaci za servis: ");
scanf("%d", &nosilo.servis);

// Snimanje novog nosila u fajl "nosila.dat"
fp = fopen("nosila.dat", "a");
if(fp==NULL){
printf("Ne postoji fajl nosila.dat, molimo vas da ga napravite\n");
return 0;
}
fwrite(&nosilo, sizeof(nosilo), 1, fp);
fclose(fp);
printf("Nosilo uspjesno kreirano.\n");
break;

case 3:

// Trenutni broj korištenja nosila
char naziv_nosila[256];
printf("Unesite naziv nosila: ");
scanf("%s", naziv_nosila);
struct koristenje_nosilo {
char ime[256];
int trenutno_koristenja;
int sprat;
int korisnik;
int servis;
} koristenje_nosilo;

// Citanje nosila iz fajla "nosila.dat"
fp = fopen("nosila.dat", "r");
if(fp==NULL){
printf("Ne postoji fajl nosila.dat, molimo vas da ga napravite\n");
return 0;
}
while(fread(&nosilo, sizeof(nosilo), 1, fp)){
if(strcmp(nosilo.ime, naziv_nosila) == 0){
printf("Naziv nosila: %s\n", nosilo.ime);
printf("Trenutno koristenja: %d\n", koristenje_nosilo.trenutno_koristenja);
printf("Razlika izmedu trenutnog stanja i servisiranja/blokiranja: %d\n", koristenje_nosilo.korisnik - koristenje_nosilo.trenutno_koristenja + koristenje_nosilo.servis);
break;
}
}
fclose(fp);
break;

case 4:
//Nosila spremna za servis

int servisiranje[20];

// Inicijaliziraj niz na 0
for (int i = 0; i < 20; i++)
servisiranje = 0;

// Prikaz nosila koja su ispunila zadati broj
for (int i = 0; i < 20; i++) {
if (servisiranje == 1)
printf("Naziv nosila: %d\n", i);
}
// Funkcija za resetiranje nosila i
// postavljanje niza na 0
void resetNosila()
{
for (int i = 0; i < 20; i++)
servisiranje = 0;
}

case 5:
// Blokirana nosila
printf("Blokirana nosila\n");
int blokiranje[20];

// Inicijaliziraj niz na 0
for (int i = 0; i < 20; i++)
blokiranje = 0;

// Prikaz nosila koja su ispunila zadati broj
for (int i = 0; i < 20; i++) {
if (blokiranje == 1)
printf("Naziv nosila: %d\n", i);
}
case 6:
printf("Izlaz iz programa\n");
break;
default:
printf("Pogresan izbor\n");
break;
}
} while (choice != 6);

} else {
printf("Unijeli ste pogresne podatke.\n");
}
}
This code seems to have an admin login system and a menu with several options for the admin. However, it seems to be missing some functionality and the user side, which is what you are having trouble with. To print the user part, you can add a new option in the menu for the user to activate the stretcher. You can use the data created by the admin, such as the number of floors and the number of movements, to simulate the movement of the object.

Remember to keep the solution concise and limit the number of items in the list if you are generating one.

Try this : BASE on your coding

C:
#include <stdio.h>
#include <string.h>

#define MAX_USERS 10
#define MAX_NAME_LENGTH 30
#define MAX_EMAIL_LENGTH 50
#define MAX_PASSWORD_LENGTH 20

struct Admin {
  char email[MAX_EMAIL_LENGTH];
  char password[MAX_PASSWORD_LENGTH];
};

struct Elevator {
  char name[MAX_NAME_LENGTH];
  int floor_count;
  int usage_count;
  int service_threshold;
  int is_queued_for_service;
};

struct Admin admin;
struct Elevator elevators[MAX_USERS];
int elevator_count = 0;

void load_admin_data() {
  // Load admin data from "admin.dat" file
  FILE *fp = fopen("admin.dat", "r");
  if (fp == NULL) {
    printf("admin.dat file not found, please create it\n");
    return;
  }
  fread(&admin, sizeof(admin), 1, fp);
  fclose(fp);
}

int login() {
  char email[MAX_EMAIL_LENGTH], password[MAX_PASSWORD_LENGTH];
  printf("Enter email: ");
  scanf("%s", email);
  printf("Enter password: ");
  scanf("%s", password);

  // Check if the entered email and password match the admin email and password
  if (strcmp(email, admin.email) == 0 && strcmp(password, admin.password) == 0) {
    printf("You are logged in as admin\n");
    return 1;
  }

  printf("Incorrect email or password\n");
  return 0;
}

void create_new_elevator() {
  // Create a new elevator
  if (elevator_count == MAX_USERS) {
    printf("Max number of elevators reached\n");
    return;
  }

  struct Elevator new_elevator;
  printf("Enter the name of the elevator: ");
  scanf("%s", new_elevator.name);
  printf("Enter the number of floors the elevator serves: ");
  scanf("%d", &new_elevator.floor_count);
  printf("Enter the usage threshold for the elevator before service: ");
  scanf("%d", &new_elevator.service_threshold);

  elevators[elevator_count++] = new_elevator;
  printf("Elevator created successfully\n");
}

void print_elevators() {
  // Print all elevators and their current usage
  printf("Name\tFloors\tUsage\tService Threshold\n");
  for (int i = 0; i < elevator_count; i++) {
    struct Elevator elevator = elevators[i];
    printf("%s\t%d\t%d\t%d\n", elevator.name, elevator.floor_count, elevator.usage_count,
           elevator.service_threshold);
  }
}

void queue
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,979
Messages
2,570,183
Members
46,719
Latest member
login dogas.info

Latest Threads

Top