write in c++ and it needs to work on linux machine so please no conio.h or anyth
ID: 3840605 • Letter: W
Question
write in c++ and it needs to work on linux machine so please no conio.h or anything that won't let it run on linux server
Problem Description Let’s assume, UNT’s official store B&N sells items from the following two categories: Stationary Items: Book, Notebook, Scrapbook, Pen, Marker, Erasers, etc. Beverages: Mocha, Latte, Espresso, Americano, Regular, Tea, Iced Tea, Coke, etc. Create two classes named as ‘Stationary’ and ‘Beverage’. Think of proper attributes for each class. For example, each stationary item (or you can call it an object) has a name (e.g.: Book, Notebook, ….), some has specific color (pens, markers), some has length and width associated with it (Note book, Book, Scrapbook), some has the property of erasability (like good, bad, not so good) associated with it. Not all attributes fit to every type of item. But each attribute must have a ‘name’. You can think of any number of attributes that are related to these items. In order to keep the design simple, add all of these attributes to the stationary class. If some attributes are not applicable to a particular stationary item (e.g. erasability does not fit to Book or Notebook), then set it to some predefined value. For example, if you declare erasability as String, then set it to “NA” for Books and Pens. For the beverage class, you can think of basic properties as name, type (hot or cold), calories, size (tall, medium, regular, etc). All of these items from both categories should have ‘price’ associated with them. Now, create a third class: Barnes_and_Nobel. This class should contain two vectors: one is stationary and the other is beverage. Add appropriate functions (at least few constructors, one destructor, set methods, and get methods). Also, each attribute should be private and the functions should be public. Each class should have its own definition file (Stationary.h, Beverage.h, Barnes_and_Nobel.h) and own class implementation file (Stationary.cpp, Beverage.cpp, Barnes_and_Nobel.cpp). In a separate file (say, program_01.cpp), write a main function that has a user-friendly menu in it. From the menu the user can insert some stationary/beverage items into the barnes_and_nobel object, print the existing items, remove some items. I am assuming you will be using the ‘name’ attribute to find an item. Since you are allowed to use vectors, the built-in methods push_back(), erase(), and size(), etc. should help you implement the insert/delete/print operation.
Explanation / Answer
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include “conio.h”
// General Utility Functions
void cagxy(unsigned int x, unsigned int y) // Clear and Goto X,Y
{
printf(“%s[%d;%df”, CLEAR, y, x);
}
void clrscr() // Clear the Screen
{
printf(“%s”,CLEAR);
}
char getch()
{
char c;
system(“stty raw -echo”);
c=getchar();
system(“stty cooked echo”);
return c;
}
void gotox(unsigned int x)
{
printf(“[%dG”, x);
}
void gotoxy(unsigned int x, unsigned int y)
{
printf(“[%d;%df”, y, x);
}
void nocursor()
{
printf(“[?25l”);
}
void reset_video()
{
printf(“[0m”);
}
void showcursor()
{
printf(“[?25h”);
}
void textcolor(char *color)
{
printf(“%s”,color);
}
void textbackground(char color[11])
{
char col[11];
strcpy(col,color);
col[2]=’4; // The given color will be fg color. Replace ‘3’ with ‘4’.
printf(“%s”,col);
}
conio.h:
#ifndef CONIO_H
#define CONIO_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// General Utility
#define CLEAR “[2J”
#define SET11 “[1;1f” // Set the Cursor at 1,1
// Text Modification
#define BLINK_SLOW “[5m”
#define BLINK_RAPID “[6m”
// Colors
#define CC_CLEAR “[0m” // Console Color CLEAR
// FG Colours
#define BLACK “[30m”
#define RED “[31m”
#define GREEN “[32m”
#define YELLOW “[33m”
#define BLUE “[34m”
#define MAGENTA “[35m”
#define CYAN “[36m”
#define WHITE “[37m”
// FG Intense Colors
#define IBLACK “[30;1m”
#define IRED “[31;1m”
#define IGREEN “[32;1m”
#define IYELLOW “[33;1m”
#define IBLUE “[34;1m”
#define IMAGENTA “[35;1m”
#define ICYAN “[36;1m”
#define IWHITE “[37;1m”
// BG Colors
#define BGC_BLACK “[40m”
#define BGC_RED “[41m”
#define BGC_GREEN “[42m”
#define BGC_YELLOW “[43m”
#define BGC_BLUE “[44m”
#define BGC_MAGENTA “[45m”
#define BGC_CYAN “[46m”
#define BGC_WHITE “[47m”
// BG Intense Colors
#define BGC_IBLACK “[40;1m”
#define BGC_IRED “[41;1m”
#define BGC_IGREEN “[42;1m”
#define BGC_IYELLOW “[43;1m”
#define BGC_IBLUE “[44;1m”
#define BGC_IMAGENTA “[45;1m”
#define BGC_ICYAN “[46;1m”
#define BGC_IWHITE “[47;1m”
// General Utility Functions
void cagxy(unsigned int x, unsigned int y); // Clear and Goto X,Y
void clrscr(); // Clear the Screen
char getch();
void gotox(unsigned int x);
void gotoxy(unsigned int x, unsigned int y);
void nocursor();
void reset_video();
void showcursor();
void textcolor(char *color);
void textbackground(char color[11]);
#endif
Example program
The code for the program that illustrates the use of our conio is given below:
test.c:
#include <stdio.h>
#include “conio.h”
int main()
{
textbackground(BLUE);
textcolor(WHITE);
clrscr();
printf(“Hello, World! ”);
getch();
return 0;
}
See how short test.c is compared to Code 2!
Now, to compile this code,
1) Keep both conio.c and conio.h in the same directory where test.c exists.
2) Compile using the following command:
gcc test.c conio.c -o test
Now, you can use conio.c and conio.h for any program.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.