Question

Create a Chat class: A chat is a message consisting of 140 characters or less. It...

Create a Chat class: A chat is a message consisting of 140 characters or less. It also has an author and a time stamp.

Write a main program that nicely demonstrates the usage of your class. Hard code a vector of 3 chats. no user input

can you please make sure to add the time stamp similar to a text message output

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//chat.h

#pragma once

#include<iostream>

#include<string.h>

#include<ctime>

using namespace std;

class chat

{

char message[140];

char author[20];

char current_time[40];

public:

void setMessage(char *msg);

void setAuthor(char *s);

void display_message();

chat(string au, string message);

};

--------------------------------------------------

//chat.cpp

#define _CRT_SECURE_NO_DEPRECATE

#define _CRT_SECURE_NO_WARNINGS

#include"chat.h"

chat::chat(string au, string msg)

{

strcpy(author, au.c_str());

strcpy(message, msg.c_str());

time_t cur = time(0);

struct tm ts;

char buf[80];

ts = *localtime(&cur);

strftime(buf, sizeof(buf), "%Y-%m-%d.%X", &ts);

strcpy(current_time, buf);

}

void chat::setMessage(char *msg)

{

strcpy(message, msg);

}

void chat::setAuthor(char *s)

{

strcpy(author, s);

}

void chat::display_message()

{

cout << "Author: " << author << endl;

cout << "Message: \n" << message << endl;

cout << current_time << endl;

}

---------------------------------------------------------

//main.cpp and output

#define _CRT_SECURE_NO_DEPRECATE

#define _CRT_SECURE_NO_WARNINGS

#include<iostream>

#include<string>

#include<vector>

#include<ctime>

#include"chat.h"

using namespace std;

int main()

{

//create chat object

vector<chat*> chats;

chats.push_back(new chat("Joan", "Hello how are u?"));

chats.push_back(new chat("Mary", "Hi Joan , Good morning"));

chats.push_back(new chat("Sara", "Hi Mary , hope you are doing good"));

//print messages

for (int i = 0; i < chats.size(); i++)

{

chats[i]->display_message();

}

}

/*output

Author: Joan

Message:

Hello how are u?

2018-12-01.10:52:33

Author: Mary

Message:

Hi Joan , Good morning

2018-12-01.10:52:33

Author: Sara

Message:

Hi Mary , hope you are doing good

2018-12-01.10:52:33

*/

Add a comment
Know the answer?
Add Answer to:
Create a Chat class: A chat is a message consisting of 140 characters or less. It...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In this homework, you will create a class that stores a list of transactions and computes...

    In this homework, you will create a class that stores a list of transactions and computes the average transaction for a given month. The user must input the name of the month and the transactions into the terminal. The Transaction_List Class First you will create two C++ files called abc1234_Transaction_List.h and abc1234_Transaction_List.cpp. Below is a UML class diagram that shows the basic design of the Transaction_List class. Transaction List -month : string transactions: vector-sdouble - num transactions: int +Transaction Listim...

  • Language : JAVA Part A Create a class CompanyDoc, representing an official document used by a...

    Language : JAVA Part A Create a class CompanyDoc, representing an official document used by a company. Give it a String title and an int length. Throughout the class, use the this. notation rather than bare instance variables and method calls.   Add a default constructor. Add a parameterized constructor that takes a value for title. Use this( appropriately to call one constructor from another. Add a toString(), which returns a string with the title, and the length in parentheses. So...

  • PLEASE INCLUDE COMMENTS In java Create a Java Program Add the following comments at the beginning...

    PLEASE INCLUDE COMMENTS In java Create a Java Program Add the following comments at the beginning of the file: Your name. The name of the class(es) used in the program. The core concept (found below) for this lesson. The date the program was written. Include a recursive method separate from the main method that will add together all of the even numbers between and including 1 and the value the user supplies. For instance, if the user enters 10 then...

  • Final PYTHON program: Create a home inventory class that will be used by a National Builder...

    Final PYTHON program: Create a home inventory class that will be used by a National Builder to maintain inventory of available houses in the country. The following attributes should be present in your home class: -private int squarefeet -private string address -private string city -private string state -private int zipcode -private string Modelname -private string salestatus (sold, available, under contract) Your program should have appropriate methods such as: -constructor -add a new home -remove a home -update home attributes At...

  • create java application with the following specifications: -create an employee class with the following attibutes: name...

    create java application with the following specifications: -create an employee class with the following attibutes: name and salary -add constuctor with arguments to initialize the attributes to valid values -write corresponding get and set methods for the attributes -add a method in Employee called verify() that returns true/false and validates that the salary falls in range1,000.00-99,999.99 Add a test application class to allow the user to enter employee information and display output: -using input(either scanner or jOption), allow user to...

  • Please write code using Python. Rubric Assignment Solution Total: 100 pts Program successfully retrieves and validates...

    Please write code using Python. Rubric Assignment Solution Total: 100 pts Program successfully retrieves and validates user input 15 pts Morse Code Function Created 10 pts Function Uses Parameters to get input message 15 pts Function successfully converts passed message to Morse Code and returns the Morse Code equivalent of message 45 pts Program calls Morse Code function and outputs the result of the function (i.e. the actual Morse Code) 15 pts Main Function Requirement Part 2 MUST have a...

  • Java program Program: Grade Stats In this program you will create a utility to calculate and...

    Java program Program: Grade Stats In this program you will create a utility to calculate and display various statistics about the grades of a class. In particular, you will read a CSV file (comma separated value) that stores the grades for a class, and then print out various statistics, either for the whole class, individual assignments, or individual students Things you will learn Robustly parsing simple text files Defining your own objects and using them in a program Handling multiple...

  • JAVA Problem Description: For this assignment, you will be writing your own exception class and you...

    JAVA Problem Description: For this assignment, you will be writing your own exception class and you will handle run-time exceptions resulting from one particular input situation. Specifics: 1) Design and implement a program that has an exception class called StringTooLongException, designed to be thrown when a string is discovered that has too many characters in it. 2) In the main driver of the program (call this class MyExceptionTest), read strings from the user until the user enters “DONE”. If a...

  • Step 2: Create the method specified below. static int GetValidWidth(string prompt) Input parameters prompt: message for...

    Step 2: Create the method specified below. static int GetValidWidth(string prompt) Input parameters prompt: message for user describing the input required Returns A non-zero width entered by the user Step 3: Create the method specified below. static int GetValidHeight(string prompt) Input parameters prompt: message for user describing the input required Returns A non-zero positive height entered by the user Step 4: Create the method specified below. static void DisplayBox(int width, int height, char fillChar) Input parameters width: width of each...

  • Homework 3: Input Validation 1   Objectives control structures console-based user input using Scanner class writing complete...

    Homework 3: Input Validation 1   Objectives control structures console-based user input using Scanner class writing complete programs using two classes: client and supplier 2   User Interface Specification This is a console-based I/O program. Display should go to System.out (print or println) and the program will get user input using the Scanner class. The flow of execution should be as follows: When the program starts, display a one-line introduction to the user Display a menu with 5 options 1. validate zip...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT