-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev1.cpp
More file actions
78 lines (65 loc) · 1.5 KB
/
Copy pathdev1.cpp
File metadata and controls
78 lines (65 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* This is the outline of a program that prints a prompt, along with it's answer from an API, using an object for each prompt's details
*/
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
class JSON
{
private:
char Prompt[1000000]; //creates a character array or string for storing the prompt
char Message[1000000]; //creates a character array or string for storing the response
long TimeSent;
long TimeRecvd;
char Source[30];
public:
void OpenFile()
{
ifstream fin1; //object creation
ofstream fout1; //object creation
fin1.open("input.txt"); //opens the file to get the input
fout1.open("output.json"); //opens the file to write the output in
}
int Task()
{
Prompt=fin1.getline(); //store prompt
/*
Get timesent
Call the API and pass string Prompt to it
Store answer in string Message
Get source
---CODE---
*/
print();
//to return if end of file
if(fin1==true)
return 1;
else
return 0;
}
void print()
{
fout1<<"{";<<endl;
fout1<<"\"Prompt\":"+Prompt<<endl;
fout1<<"\"Message\":"+Message<<endl;
fout1<<"\"TimeSent\":"+TimeSent<<endl;
//get time received
fout1<<"\"TimeRecvd\":"+TimeRecvd<<endl;
fout1<<"\"Source\":"+Source+"}\n\n";
}
void CloseFile()
{
fin1.close();
fout1.close(); //closes both the files
}
};
void main()
{
JSON obj[];//array of objects with dynamic allocation of memory, for as many prompts as there are
int i=1; //a flag to mark the end of file
int j=0; //index for object array
while(i!=0)
{
i=obj[j].Task();
j++;
}
}