Demo entry 6687280

курсовая работа

   

Submitted by anonymous on Dec 27, 2017 at 18:55
Language: C++. Code size: 3.5 kB.

#include <stdio.h>
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;

struct Date {
	short int day;
	short int month;
	short int year;
};
	
struct Begin {
	short int hour;
	short int min;
};
	
struct End {
	short int hour;
	short int min;
};	

struct People {
	string firstName;
	int phoneNumber;
	// date of blabla
	Date date;
	
	// price of per minute
	short int tariff;
	
	// time begin and end
	Begin begin;
	End end;
	
	short int deltaTime;
	
	People* next;
};

void add(People* people) {
	cout << "Enter First Name: ";
	cin >> people->firstName;
	
	cout << "Enter date of blabla (day, month, year)"<< endl;
	cin >> people->date.day;
	cin >> people->date.month;
	cin >> people->date.year;
	
	cout << "Price of per minute: ";
	cin >> people->tariff;
	
	cout << "Enter time Begin (hour, minute)" << endl;
	cin >> people->begin.hour;
	cin >> people->begin.min;
	
	cout << "Enter time End (hour, minute)" << endl;
	cin >> people->end.hour;
	cin >> people->end.min;
	
	people->deltaTime = (people->end.hour * 60 + people->end.min) - (people->begin.hour * 60 + people->begin.min);
	
	system("cls");
}

void view(People* people) {
	cout << "=============================================" << endl;
	cout << "First Name: " << people->firstName << endl;
	printf("Date of blabla: %d.%d.%d\n", people->date.day, people->date.month, people->date.year);
	cout << "Price of per minute: " << people->tariff << endl;
	cout << "time Begin: " << people->begin.hour << ":" << people->begin.min << endl;
	cout << "time End " << people->end.hour << ":" << people->end.min << endl;
	cout << "Duration of the call: " << people->deltaTime << endl;
}

void viewAll(People* first, short int count) {
	People* nextPeople;
	nextPeople = first;
	for (int i=0; i<count; i++) {
		view(nextPeople);
		nextPeople = nextPeople->next;
		cout << "=============================================" << endl;
	}
}

void searchDuration(People* first, short int count) {
	People* nextPeople;
	nextPeople = first;
	short int duration;
	cout << "Enter the duration of the call: ";
	cin >> duration;
	for (int i=0; i<count; i++) {
		if (nextPeople->deltaTime > duration){
			view(nextPeople);
		}
		nextPeople = nextPeople->next;
	}
}

void sort(People* first, short int count){
	People* thisPeople;
	People* nextPeople;
	People* buff;
	People* priorPeople;
	thisPeople = first;
	for (int i=0; i<count; i++) {
		nextPeople = thisPeople->next;
		if(thisPeople->deltaTime > nextPeople->deltaTime && i==0){
			thisPeople->next = nextPeople->next;
			nextPeople->next = thisPeople;	
		}		
		if(thisPeople->deltaTime > nextPeople->deltaTime && i>0){
			priorPeople->next = nextPeople;
			thisPeople->next = nextPeople->next;
			nextPeople->next = thisPeople;		
		}	
		priorPeople = thisPeople;
		thisPeople = thisPeople->next;
	}
}

void searchFirstName(){
	//
}


main() {
	int count = 0, i;
	People* first = new People;
	People* people = first;
	add(first);
	count++;
	bool exit = false;
	while(exit != true) {
		cout << "Enter 1-for exit, 0 to be continue: ";
		cin >> exit;
		system("cls");
		if (exit!=true){
			people->next = new People;
			people = people->next;
			add(people);
			count++;	
		}
	}
	
	// Output all list
	viewAll(first, count);
	
	// Search the duration of the call
	searchDuration(first, count);
	
	// Sort list
	sort(first, count);
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).