SlideShare a Scribd company logo
C++- Help with the section for getNextId only.
// Program to implement a very simplified list of tweets
// from a single simulated Twitter account
// Tweets can be added, deleted, and liked
#include <iostream>
using namespace std;
const int MSGSIZE = 100; // Maximum size for a tweet message
const int CAPACITY = 10; // Maximum number of tweets
// Structure used to define a tweet entry
struct Tweet
{
int id;
char msg[MSGSIZE];
int likes;
};
/*
* Prints out an entire timeline to the screen
* timeline = timeline of tweets to be printed
* usedSize = number of tweets in the timeline
* selected = position number of currently selected tweet
*/
void displayTimeline(const Tweet timeline[], int usedSize, int selected);
/*
* Edits currently selected tweet
* with a new message entered by the user.
* timeline = timeline in which the tweet is to be edited
* usedSize = number of tweets in the timeline
* selected = position number of currently selected tweet
* If 'selected' represents a valid array position, the
* selected tweet will be updated.
* If 'selected' is not valid a 'no tweet is selected message' will be
* displayed and no changes will be made.
*/
void doEditTweet(Tweet timeline[], int usedSize, int selected);
/*
* Adds a like to the currently selected tweet.
* timeline = timeline in which the tweet is to be edited
* usedSize = number of tweets in the timeline
* selected = position number of currently selected tweet
* If 'selected' represents a valid array position, the
* selected tweet will be updated.
* If 'selected' is not valid a 'no tweet is selected message' will be
* displayed and no changes will be made.
*/
void doLikeTweet(Tweet timeline[], int usedSize, int selected);
/*
* Deleted currently selected tweet.
* timeline = timeline in from which the entry is to be deleted
* usedSize = number of tweets in the timeline
* If 'selected' represents a valid array position:
* the selected tweet will be deleted
* usedSize will be updated to reflect the updated number of tweets in the timeline
* selected will be updated to -1
* If 'selected' is not valid a 'no tweet is selected message' will be
* displayed and no changes will be made.
*/
void doDeleteTweet(Tweet timeline[], int& usedSize, int& selected);
/*
* If there is room in the timeline for new tweets, then this gets
* a new tweet from the user and adds it to the timeline.
* timeline = timeline in which the tweet is to be added
* usedSize = number of tweets in the timeline
* If tweet was able to be added, returns the position number in the
* timeline of where the item was added, and usedSize will be
* updated to reflect the number of tweets now in the timeline.
* If tweet was not able to be added, returns -1, and usedSize
* remains unchanged.
*/
int doAddTweet(Tweet timeline[], int& usedSize);
/*
* Adds a new tweet to the list
* timeline = timeline in which the entry is to be added
* usedSize = number of tweets in the timeline
* message = tweet message to be added
* If tweet was able to be added, returns the position number in the
* timeline of where the item was added, and usedSize will be
* updated to reflect the number of tweets now in the timeline.
* If tweet was not able to be added, returns -1, and usedSize
* remains unchanged.
*/
int addTweet(Tweet timeline[], int& usedSize, const char message[]);
/*
* Returns the next available ID number
* timeline = timeline in which to find the highest ID
* usedSize = number of tweets in the timeline
* If timeline is empty, returns 100;
* otherwise, returns 1 + highest ID number in the timeline
*/
int getNextId(Tweet timeline[], int usedSize);
/*
* Gets a tweet id from the user. Searches a timeline to try
* to find the specified tweet by its id.
* timeline = timeline to be searched
* usedSize = number of tweets in the timeline
* If the tweet is found, the position number of where the tweet
* is stored in the timeline will be returned. If the tweet is
* not found, a 'not found message' will be printed, and
* the value -1 will be returned.
* If timeline is empty, an 'empty' message will be printed, and
* the value -1 will be returned.
*/
int selectTweet(const Tweet timeline[], int usedSize);
int main()
{
Tweet timeline[CAPACITY]; // Twitter timeline
int choice; // User's menu choice
int usedSize = 0; // Num of tweets in the timeline
int selected = -1; // Currently selected tweet
int tmp; // Temporary variable
// Add some starter entries for testing purposes
selected = addTweet(timeline, usedSize, "Where do they get the seeds to plant seedless
watermelons?");
selected = addTweet(timeline, usedSize, "Waffles are just pancakes with convenient boxes to hold
your syrup.");
selected = addTweet(timeline, usedSize, "Last night I even struck up a conversation with a spider.
Turns out he's a web designer.");
do
{
cout << "1. Display Timelinen";
cout << "2. Select Tweetn";
cout << "3. Add New Tweetn";
cout << "4. Edit Selected Tweetn";
cout << "5. Like Selected Tweetn";
cout << "6. Delete Tweetn";
cout << "7. Exitn";
cout << endl;
cout << "Select: ";
// Get the numeric entry from the menu
cin >> choice;
// Corrects issues where user might enter a non-integer value
while (cin.fail())
{
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), 'n');
cout << "Select: ";
cin >> choice;
}
// Makes the 'enter' key that was pressed after the numeric entry be ignored
// Should be used after getting any numeric input from the keyboard
cin.ignore();
switch (choice)
{
case 1:
displayTimeline(timeline, usedSize, selected);
break;
case 2:
tmp = selectTweet(timeline, usedSize);
// if selected tweet exists, update selected variable;
// otherwise leave it unchanged
if (tmp > -1)
selected = tmp;
break;
case 3:
tmp = doAddTweet(timeline, usedSize);
// if tweet was added, make it be the selected tweet;
// otherwise leave it unchanged
if (tmp > -1)
selected = tmp;
break;
case 4:
doEditTweet(timeline, usedSize, selected);
break;
case 5:
doLikeTweet(timeline, usedSize, selected);
break;
case 6:
doDeleteTweet(timeline, usedSize, selected);
break;
}
} while (choice != 7);
return 0;
}
int doAddTweet(Tweet timeline[], int& usedSize)
{
// TODO: Write code for the function
return -1;
}
void doEditTweet(Tweet timeline[], int usedSize, int selected)
{
// TODO: Write code for the function
}
void doLikeTweet(Tweet timeline[], int usedSize, int selected)
{
// TODO: Write code for the function
}
void displayTimeline(const Tweet timeline[], int usedSize, int selected)
{
// TODO: Write code for the function
}
int addTweet(Tweet timeline[], int& usedSize, const char message[])
{
// TODO: Write code for the function
return -1;
}
int getNextId(Tweet timeline[], int usedSize)
{
// TODO: Write code for the function
return 100;
}
void doDeleteTweet(Tweet timeline[], int& usedSize, int& selected)
{
if (selected == -1)
{
cout << "no tweet is selected" << endl;
}
else
{
selected = -1;
usedSize = usedSize - 1;
}
}
int selectTweet(const Tweet timeline[], int usedSize)
{
return -1;
}

More Related Content

More from jaipur2

Business inventories increased 19 billion in the second qua.pdf
Business inventories increased 19 billion in the second qua.pdfBusiness inventories increased 19 billion in the second qua.pdf
Business inventories increased 19 billion in the second qua.pdf
jaipur2
 
Bu yaz kamyonu farkl yerel topluluk etkinliklerine gtryor.pdf
Bu yaz kamyonu farkl yerel topluluk etkinliklerine gtryor.pdfBu yaz kamyonu farkl yerel topluluk etkinliklerine gtryor.pdf
Bu yaz kamyonu farkl yerel topluluk etkinliklerine gtryor.pdf
jaipur2
 
BU Contractors received a contract to construct an office bu.pdf
BU Contractors received a contract to construct an office bu.pdfBU Contractors received a contract to construct an office bu.pdf
BU Contractors received a contract to construct an office bu.pdf
jaipur2
 
Bu senaryo bir geici zm en iyi ekilde aklar Etkili.pdf
Bu senaryo bir geici zm en iyi ekilde aklar   Etkili.pdfBu senaryo bir geici zm en iyi ekilde aklar   Etkili.pdf
Bu senaryo bir geici zm en iyi ekilde aklar Etkili.pdf
jaipur2
 
Bu durum iin tam binom olaslk dalmn sadaki bir tabloda olut.pdf
Bu durum iin tam binom olaslk dalmn sadaki bir tabloda olut.pdfBu durum iin tam binom olaslk dalmn sadaki bir tabloda olut.pdf
Bu durum iin tam binom olaslk dalmn sadaki bir tabloda olut.pdf
jaipur2
 
Bu derste T hcreleri iin merkezi ve evresel tolerans mek.pdf
Bu derste T hcreleri iin merkezi ve evresel tolerans mek.pdfBu derste T hcreleri iin merkezi ve evresel tolerans mek.pdf
Bu derste T hcreleri iin merkezi ve evresel tolerans mek.pdf
jaipur2
 
Bullseye Corp is a private company in the state of Illinois .pdf
Bullseye Corp is a private company in the state of Illinois .pdfBullseye Corp is a private company in the state of Illinois .pdf
Bullseye Corp is a private company in the state of Illinois .pdf
jaipur2
 
Bulging and herniated discs can cause major problems when th.pdf
Bulging and herniated discs can cause major problems when th.pdfBulging and herniated discs can cause major problems when th.pdf
Bulging and herniated discs can cause major problems when th.pdf
jaipur2
 
Bullying according to noted expert Dan Olweus poisons t.pdf
Bullying according to noted expert Dan Olweus poisons t.pdfBullying according to noted expert Dan Olweus poisons t.pdf
Bullying according to noted expert Dan Olweus poisons t.pdf
jaipur2
 
C++ Please I am posting the fifth time and hoping to get th.pdf
C++ Please I am posting the fifth time and hoping to get th.pdfC++ Please I am posting the fifth time and hoping to get th.pdf
C++ Please I am posting the fifth time and hoping to get th.pdf
jaipur2
 
C++ only plz Write a function that takes two arguments and .pdf
C++ only  plz Write a function that takes two arguments and .pdfC++ only  plz Write a function that takes two arguments and .pdf
C++ only plz Write a function that takes two arguments and .pdf
jaipur2
 
C++ only 319 LAB Exact change Write a program with total c.pdf
C++ only 319 LAB Exact change Write a program with total c.pdfC++ only 319 LAB Exact change Write a program with total c.pdf
C++ only 319 LAB Exact change Write a program with total c.pdf
jaipur2
 
C++ Help with the section for doEditTweet only Program .pdf
C++ Help with the section for doEditTweet only  Program .pdfC++ Help with the section for doEditTweet only  Program .pdf
C++ Help with the section for doEditTweet only Program .pdf
jaipur2
 
C++ is a highlevel programming language that consists of v.pdf
C++ is a highlevel programming language that consists of v.pdfC++ is a highlevel programming language that consists of v.pdf
C++ is a highlevel programming language that consists of v.pdf
jaipur2
 
C++ Programming Exercise 9 from Chapter 16 Upload your so.pdf
C++  Programming Exercise 9 from Chapter 16 Upload your so.pdfC++  Programming Exercise 9 from Chapter 16 Upload your so.pdf
C++ Programming Exercise 9 from Chapter 16 Upload your so.pdf
jaipur2
 
BU RESTORAN KURTARILABLR M Juan ve Bonita Gonzales Ohio .pdf
BU RESTORAN KURTARILABLR M  Juan ve Bonita Gonzales Ohio .pdfBU RESTORAN KURTARILABLR M  Juan ve Bonita Gonzales Ohio .pdf
BU RESTORAN KURTARILABLR M Juan ve Bonita Gonzales Ohio .pdf
jaipur2
 
C Sao Paulodaki Lumiar okulunda snf ev devi veya oyun zam.pdf
C Sao Paulodaki Lumiar okulunda snf ev devi veya oyun zam.pdfC Sao Paulodaki Lumiar okulunda snf ev devi veya oyun zam.pdf
C Sao Paulodaki Lumiar okulunda snf ev devi veya oyun zam.pdf
jaipur2
 
Bu eitim modlnde sunulan biyolojik tehlike tanmndaki gve.pdf
Bu eitim modlnde sunulan biyolojik tehlike tanmndaki gve.pdfBu eitim modlnde sunulan biyolojik tehlike tanmndaki gve.pdf
Bu eitim modlnde sunulan biyolojik tehlike tanmndaki gve.pdf
jaipur2
 
C problem 1 Create Ellipse object Ellipse set fill to Col.pdf
C problem 1 Create Ellipse object Ellipse set fill to Col.pdfC problem 1 Create Ellipse object Ellipse set fill to Col.pdf
C problem 1 Create Ellipse object Ellipse set fill to Col.pdf
jaipur2
 
C Program Jrite a program called that prompts the user to en.pdf
C Program Jrite a program called that prompts the user to en.pdfC Program Jrite a program called that prompts the user to en.pdf
C Program Jrite a program called that prompts the user to en.pdf
jaipur2
 

More from jaipur2 (20)

Business inventories increased 19 billion in the second qua.pdf
Business inventories increased 19 billion in the second qua.pdfBusiness inventories increased 19 billion in the second qua.pdf
Business inventories increased 19 billion in the second qua.pdf
 
Bu yaz kamyonu farkl yerel topluluk etkinliklerine gtryor.pdf
Bu yaz kamyonu farkl yerel topluluk etkinliklerine gtryor.pdfBu yaz kamyonu farkl yerel topluluk etkinliklerine gtryor.pdf
Bu yaz kamyonu farkl yerel topluluk etkinliklerine gtryor.pdf
 
BU Contractors received a contract to construct an office bu.pdf
BU Contractors received a contract to construct an office bu.pdfBU Contractors received a contract to construct an office bu.pdf
BU Contractors received a contract to construct an office bu.pdf
 
Bu senaryo bir geici zm en iyi ekilde aklar Etkili.pdf
Bu senaryo bir geici zm en iyi ekilde aklar   Etkili.pdfBu senaryo bir geici zm en iyi ekilde aklar   Etkili.pdf
Bu senaryo bir geici zm en iyi ekilde aklar Etkili.pdf
 
Bu durum iin tam binom olaslk dalmn sadaki bir tabloda olut.pdf
Bu durum iin tam binom olaslk dalmn sadaki bir tabloda olut.pdfBu durum iin tam binom olaslk dalmn sadaki bir tabloda olut.pdf
Bu durum iin tam binom olaslk dalmn sadaki bir tabloda olut.pdf
 
Bu derste T hcreleri iin merkezi ve evresel tolerans mek.pdf
Bu derste T hcreleri iin merkezi ve evresel tolerans mek.pdfBu derste T hcreleri iin merkezi ve evresel tolerans mek.pdf
Bu derste T hcreleri iin merkezi ve evresel tolerans mek.pdf
 
Bullseye Corp is a private company in the state of Illinois .pdf
Bullseye Corp is a private company in the state of Illinois .pdfBullseye Corp is a private company in the state of Illinois .pdf
Bullseye Corp is a private company in the state of Illinois .pdf
 
Bulging and herniated discs can cause major problems when th.pdf
Bulging and herniated discs can cause major problems when th.pdfBulging and herniated discs can cause major problems when th.pdf
Bulging and herniated discs can cause major problems when th.pdf
 
Bullying according to noted expert Dan Olweus poisons t.pdf
Bullying according to noted expert Dan Olweus poisons t.pdfBullying according to noted expert Dan Olweus poisons t.pdf
Bullying according to noted expert Dan Olweus poisons t.pdf
 
C++ Please I am posting the fifth time and hoping to get th.pdf
C++ Please I am posting the fifth time and hoping to get th.pdfC++ Please I am posting the fifth time and hoping to get th.pdf
C++ Please I am posting the fifth time and hoping to get th.pdf
 
C++ only plz Write a function that takes two arguments and .pdf
C++ only  plz Write a function that takes two arguments and .pdfC++ only  plz Write a function that takes two arguments and .pdf
C++ only plz Write a function that takes two arguments and .pdf
 
C++ only 319 LAB Exact change Write a program with total c.pdf
C++ only 319 LAB Exact change Write a program with total c.pdfC++ only 319 LAB Exact change Write a program with total c.pdf
C++ only 319 LAB Exact change Write a program with total c.pdf
 
C++ Help with the section for doEditTweet only Program .pdf
C++ Help with the section for doEditTweet only  Program .pdfC++ Help with the section for doEditTweet only  Program .pdf
C++ Help with the section for doEditTweet only Program .pdf
 
C++ is a highlevel programming language that consists of v.pdf
C++ is a highlevel programming language that consists of v.pdfC++ is a highlevel programming language that consists of v.pdf
C++ is a highlevel programming language that consists of v.pdf
 
C++ Programming Exercise 9 from Chapter 16 Upload your so.pdf
C++  Programming Exercise 9 from Chapter 16 Upload your so.pdfC++  Programming Exercise 9 from Chapter 16 Upload your so.pdf
C++ Programming Exercise 9 from Chapter 16 Upload your so.pdf
 
BU RESTORAN KURTARILABLR M Juan ve Bonita Gonzales Ohio .pdf
BU RESTORAN KURTARILABLR M  Juan ve Bonita Gonzales Ohio .pdfBU RESTORAN KURTARILABLR M  Juan ve Bonita Gonzales Ohio .pdf
BU RESTORAN KURTARILABLR M Juan ve Bonita Gonzales Ohio .pdf
 
C Sao Paulodaki Lumiar okulunda snf ev devi veya oyun zam.pdf
C Sao Paulodaki Lumiar okulunda snf ev devi veya oyun zam.pdfC Sao Paulodaki Lumiar okulunda snf ev devi veya oyun zam.pdf
C Sao Paulodaki Lumiar okulunda snf ev devi veya oyun zam.pdf
 
Bu eitim modlnde sunulan biyolojik tehlike tanmndaki gve.pdf
Bu eitim modlnde sunulan biyolojik tehlike tanmndaki gve.pdfBu eitim modlnde sunulan biyolojik tehlike tanmndaki gve.pdf
Bu eitim modlnde sunulan biyolojik tehlike tanmndaki gve.pdf
 
C problem 1 Create Ellipse object Ellipse set fill to Col.pdf
C problem 1 Create Ellipse object Ellipse set fill to Col.pdfC problem 1 Create Ellipse object Ellipse set fill to Col.pdf
C problem 1 Create Ellipse object Ellipse set fill to Col.pdf
 
C Program Jrite a program called that prompts the user to en.pdf
C Program Jrite a program called that prompts the user to en.pdfC Program Jrite a program called that prompts the user to en.pdf
C Program Jrite a program called that prompts the user to en.pdf
 

Recently uploaded

Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
Bisnar Chase Personal Injury Attorneys
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
Assessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptxAssessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptx
Kavitha Krishnan
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 

Recently uploaded (20)

Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
Assessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptxAssessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptx
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 

C++ Help with the section for getNextId only Program to.pdf

  • 1. C++- Help with the section for getNextId only. // Program to implement a very simplified list of tweets // from a single simulated Twitter account // Tweets can be added, deleted, and liked #include <iostream> using namespace std; const int MSGSIZE = 100; // Maximum size for a tweet message const int CAPACITY = 10; // Maximum number of tweets // Structure used to define a tweet entry struct Tweet { int id; char msg[MSGSIZE]; int likes; }; /* * Prints out an entire timeline to the screen * timeline = timeline of tweets to be printed * usedSize = number of tweets in the timeline * selected = position number of currently selected tweet */ void displayTimeline(const Tweet timeline[], int usedSize, int selected); /* * Edits currently selected tweet * with a new message entered by the user. * timeline = timeline in which the tweet is to be edited * usedSize = number of tweets in the timeline * selected = position number of currently selected tweet * If 'selected' represents a valid array position, the * selected tweet will be updated. * If 'selected' is not valid a 'no tweet is selected message' will be * displayed and no changes will be made. */ void doEditTweet(Tweet timeline[], int usedSize, int selected); /* * Adds a like to the currently selected tweet. * timeline = timeline in which the tweet is to be edited * usedSize = number of tweets in the timeline * selected = position number of currently selected tweet * If 'selected' represents a valid array position, the * selected tweet will be updated. * If 'selected' is not valid a 'no tweet is selected message' will be * displayed and no changes will be made.
  • 2. */ void doLikeTweet(Tweet timeline[], int usedSize, int selected); /* * Deleted currently selected tweet. * timeline = timeline in from which the entry is to be deleted * usedSize = number of tweets in the timeline * If 'selected' represents a valid array position: * the selected tweet will be deleted * usedSize will be updated to reflect the updated number of tweets in the timeline * selected will be updated to -1 * If 'selected' is not valid a 'no tweet is selected message' will be * displayed and no changes will be made. */ void doDeleteTweet(Tweet timeline[], int& usedSize, int& selected); /* * If there is room in the timeline for new tweets, then this gets * a new tweet from the user and adds it to the timeline. * timeline = timeline in which the tweet is to be added * usedSize = number of tweets in the timeline * If tweet was able to be added, returns the position number in the * timeline of where the item was added, and usedSize will be * updated to reflect the number of tweets now in the timeline. * If tweet was not able to be added, returns -1, and usedSize * remains unchanged. */ int doAddTweet(Tweet timeline[], int& usedSize); /* * Adds a new tweet to the list * timeline = timeline in which the entry is to be added * usedSize = number of tweets in the timeline * message = tweet message to be added * If tweet was able to be added, returns the position number in the * timeline of where the item was added, and usedSize will be * updated to reflect the number of tweets now in the timeline. * If tweet was not able to be added, returns -1, and usedSize * remains unchanged. */ int addTweet(Tweet timeline[], int& usedSize, const char message[]); /* * Returns the next available ID number * timeline = timeline in which to find the highest ID * usedSize = number of tweets in the timeline * If timeline is empty, returns 100; * otherwise, returns 1 + highest ID number in the timeline
  • 3. */ int getNextId(Tweet timeline[], int usedSize); /* * Gets a tweet id from the user. Searches a timeline to try * to find the specified tweet by its id. * timeline = timeline to be searched * usedSize = number of tweets in the timeline * If the tweet is found, the position number of where the tweet * is stored in the timeline will be returned. If the tweet is * not found, a 'not found message' will be printed, and * the value -1 will be returned. * If timeline is empty, an 'empty' message will be printed, and * the value -1 will be returned. */ int selectTweet(const Tweet timeline[], int usedSize); int main() { Tweet timeline[CAPACITY]; // Twitter timeline int choice; // User's menu choice int usedSize = 0; // Num of tweets in the timeline int selected = -1; // Currently selected tweet int tmp; // Temporary variable // Add some starter entries for testing purposes selected = addTweet(timeline, usedSize, "Where do they get the seeds to plant seedless watermelons?"); selected = addTweet(timeline, usedSize, "Waffles are just pancakes with convenient boxes to hold your syrup."); selected = addTweet(timeline, usedSize, "Last night I even struck up a conversation with a spider. Turns out he's a web designer."); do { cout << "1. Display Timelinen"; cout << "2. Select Tweetn"; cout << "3. Add New Tweetn"; cout << "4. Edit Selected Tweetn"; cout << "5. Like Selected Tweetn"; cout << "6. Delete Tweetn"; cout << "7. Exitn"; cout << endl; cout << "Select: "; // Get the numeric entry from the menu cin >> choice; // Corrects issues where user might enter a non-integer value
  • 4. while (cin.fail()) { cin.clear(); cin.ignore(numeric_limits<streamsize>::max(), 'n'); cout << "Select: "; cin >> choice; } // Makes the 'enter' key that was pressed after the numeric entry be ignored // Should be used after getting any numeric input from the keyboard cin.ignore(); switch (choice) { case 1: displayTimeline(timeline, usedSize, selected); break; case 2: tmp = selectTweet(timeline, usedSize); // if selected tweet exists, update selected variable; // otherwise leave it unchanged if (tmp > -1) selected = tmp; break; case 3: tmp = doAddTweet(timeline, usedSize); // if tweet was added, make it be the selected tweet; // otherwise leave it unchanged if (tmp > -1) selected = tmp; break; case 4: doEditTweet(timeline, usedSize, selected); break; case 5: doLikeTweet(timeline, usedSize, selected); break; case 6: doDeleteTweet(timeline, usedSize, selected); break; } } while (choice != 7); return 0; }
  • 5. int doAddTweet(Tweet timeline[], int& usedSize) { // TODO: Write code for the function return -1; } void doEditTweet(Tweet timeline[], int usedSize, int selected) { // TODO: Write code for the function } void doLikeTweet(Tweet timeline[], int usedSize, int selected) { // TODO: Write code for the function } void displayTimeline(const Tweet timeline[], int usedSize, int selected) { // TODO: Write code for the function } int addTweet(Tweet timeline[], int& usedSize, const char message[]) { // TODO: Write code for the function return -1; } int getNextId(Tweet timeline[], int usedSize) { // TODO: Write code for the function return 100; } void doDeleteTweet(Tweet timeline[], int& usedSize, int& selected) { if (selected == -1) { cout << "no tweet is selected" << endl; } else { selected = -1; usedSize = usedSize - 1; } }
  • 6. int selectTweet(const Tweet timeline[], int usedSize) { return -1; }