Yam Code
Sign up
Login
New paste
Home
Trending
Archive
English
English
Tiếng Việt
भारत
Sign up
Login
New Paste
Browse
#include <iostream> using namespace std; #include<stdlib.h> #include<conio.h> #define MAX 100 #include <stdio.h> #include <string.h> typedef struct COMPUTER { int ID; char brand[50]; char model[30]; char CPU[10]; int RAM; }; typedef struct NODE { COMPUTER Info; NODE *pNext; //dia chi cua ban ke tiep }; typedef struct LIST { NODE *pHead; //nguoi dau tien }; void Initialize(LIST &list) { list.pHead = NULL; } bool isEmpty(LIST list) { return list.pHead == NULL; } NODE* CreateNode(COMPUTER x) { NODE *p = new NODE; //cap phat vung nho if(p != NULL) { p->Info = x; p->pNext = NULL; } return p; } void InsertHead(LIST &list, COMPUTER x) { NODE *p = CreateNode(x); if(p!=NULL) //tao duoc NODE { p->pNext = list.pHead; list.pHead = p; } } void Input1Computer(COMPUTER &c) { cout << "Input ID: " ; cin>>c.ID; cout << "Input brand: "; cin>>c.brand; cout<<"Input model: "; cin>> c.model; cout<<"Input CPU: "; cin>>c.CPU; cout<<"Input RAM: "; cin>>c.RAM; } void CreateList(LIST &list) { COMPUTER x; char tt; do { Input1Computer(x); InsertHead(list, x); //them x vao dau danh sach cout<<"Nhan 'y'|'Y' de tiep thuc them mot may tinh"<<endl; tt = getch(); }while(tt == 'y' || tt == 'Y'); } void OutputComputer(COMPUTER c) { cout<<c.ID<<"\t"; cout<<c.brand<<"\t"; cout<<c.model<<"\t"; cout<<c.CPU<<"\t"; cout<<c.RAM<<"\n"; } void OutputList(LIST list) { for(NODE *p = list.pHead; p!=NULL; p=p->pNext) OutputComputer(p->Info); cout<<endl; } void FindComputerBrand(LIST list, char BRAND[]) { for(NODE *p = list.pHead; p!=NULL; p=p->pNext) { if(strcmp(p->Info.brand, BRAND)==0) { OutputComputer(p->Info); return; } } cout<<"KHONG TIM THAY MAY TINH CO HANG SX LA: "<<BRAND<<endl; } void FindMaxRAM(LIST list) { NODE* max = list.pHead; for(NODE *p = list.pHead; p!=NULL; p=p->pNext) { if(max->Info.RAM < p->Info.RAM) { max = p; OutputComputer(max->Info); return; } } cout<<"Can't find the computer with the highest RAM: "<<endl; } void ghiFile(LIST list) { FILE *f = fopen("Computer.txt", "wb"); if(f == NULL) { cout<<"Loi mo file"<<endl; return; } for(NODE *p = list.pHead; p!=NULL; p=p->pNext) fwrite(&p->Info, sizeof(COMPUTER), 1, f); fclose(f); } void docFile(LIST &list) { COMPUTER x; FILE *f = fopen("Computer.txt", "rb"); if(f == NULL) { cout<<"Loi mo file"<<endl; return; } //nhap1SV(x); while(!feof(f)) //khi chua het file { if(fread(&x, sizeof(COMPUTER), 1, f)) InsertHead(list, x); //them x vao dau danh sach } } void swap(COMPUTER &a, COMPUTER &b) { COMPUTER tmp = a; a=b; b=tmp; } void Sort_Decrease_RAM(LIST &list) { for(NODE*p = list.pHead; p != NULL; p = p->pNext) for(NODE*q = p; q != NULL; q = q->pNext) { if(p->Info.RAM > q->Info.RAM) swap(p->Info, q->Info); } } int main() { LIST list; Initialize(list); CreateList(list); OutputList(list); ghiFile(list); docFile(list); char brand[50]; char tt; do { cout<<"Input the brand you want to find: "; cin>>brand; FindComputerBrand(list,brand); cout<<"Press y/Y to continue to find the brand"<<endl; tt=getch(); } while(tt=='y'||tt=='Y'); cout<<"The computer with the highest RAM: "<<endl; FindMaxRAM(list); cout<<"Sap xep: "<<endl; Sort_Decrease_RAM(list); OutputList(list); }
Paste Settings
Paste Title :
[Optional]
Paste Folder :
[Optional]
Select
Syntax Highlighting :
[Optional]
Select
Markup
CSS
JavaScript
Bash
C
C#
C++
Java
JSON
Lua
Plaintext
C-like
ABAP
ActionScript
Ada
Apache Configuration
APL
AppleScript
Arduino
ARFF
AsciiDoc
6502 Assembly
ASP.NET (C#)
AutoHotKey
AutoIt
Basic
Batch
Bison
Brainfuck
Bro
CoffeeScript
Clojure
Crystal
Content-Security-Policy
CSS Extras
D
Dart
Diff
Django/Jinja2
Docker
Eiffel
Elixir
Elm
ERB
Erlang
F#
Flow
Fortran
GEDCOM
Gherkin
Git
GLSL
GameMaker Language
Go
GraphQL
Groovy
Haml
Handlebars
Haskell
Haxe
HTTP
HTTP Public-Key-Pins
HTTP Strict-Transport-Security
IchigoJam
Icon
Inform 7
INI
IO
J
Jolie
Julia
Keyman
Kotlin
LaTeX
Less
Liquid
Lisp
LiveScript
LOLCODE
Makefile
Markdown
Markup templating
MATLAB
MEL
Mizar
Monkey
N4JS
NASM
nginx
Nim
Nix
NSIS
Objective-C
OCaml
OpenCL
Oz
PARI/GP
Parser
Pascal
Perl
PHP
PHP Extras
PL/SQL
PowerShell
Processing
Prolog
.properties
Protocol Buffers
Pug
Puppet
Pure
Python
Q (kdb+ database)
Qore
R
React JSX
React TSX
Ren'py
Reason
reST (reStructuredText)
Rip
Roboconf
Ruby
Rust
SAS
Sass (Sass)
Sass (Scss)
Scala
Scheme
Smalltalk
Smarty
SQL
Soy (Closure Template)
Stylus
Swift
TAP
Tcl
Textile
Template Toolkit 2
Twig
TypeScript
VB.Net
Velocity
Verilog
VHDL
vim
Visual Basic
WebAssembly
Wiki markup
Xeora
Xojo (REALbasic)
XQuery
YAML
HTML
Paste Expiration :
[Optional]
Never
Self Destroy
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Status :
[Optional]
Public
Unlisted
Private (members only)
Password :
[Optional]
Description:
[Optional]
Tags:
[Optional]
Encrypt Paste
(
?
)
Create New Paste
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Site Languages
×
English
Tiếng Việt
भारत