#include <iostream>#include<vector>#include<string>using namespacestd;//function DeclarationvoidOUTPUT1 (vector<string> &); voidOutput2 (vector<string> &); intmain () {vector<string>likes, dislikes;//create vector<string> objects likes and dislikesLikes.push_back ("fayorite Book"); Likes.push_back ("Music"); Likes.push_back ("film"); Likes.push_back ("Paintings"); Likes.push_back ("Anime"); Likes.push_back ("Sport"); Likes.push_back ("Sportman"); //add element values for vector<string> Array object likes (favorite book, Music, film, paintings,anime,sport,sportsman,etc)//Complement Code//..... cout<<"-----I like these-----"<<Endl; OUTPUT1 (likes); //Call the child function output vector<string> Array object likes element value//Complement Code//..... Dislikes.push_back ("Suan"); Dislikes.push_back ("Cong"); //add element values for vector<string> array object dislikes//Complement Code//..... cout<<"-----I Dislike these-----"<<Endl; Output2 (dislikes); //Call the child function output vector<string> Array object dislikes element value//Complement Code//..... Likes.swap (dislikes); //exchanging element values for vector<string> objects likes and dislikes//Complement Code//..... cout<<"-----I likes these-----"<<Endl; OUTPUT1 (likes); //Call the child function output vector<string> Array object likes element value//Complement Code//..... cout<<"-----I Dislikes these-----"<<Endl; Output2 (dislikes); //Call the child function output vector<string> Array object dislikes element value//Complement Code//..... return 0;}//function Implementation//output The element value of the vector<string> array Object v with the following labelvoidOUTPUT1 (vector<string> &v) { for(intI=0; I<v.size (); i++) cout<<v[i]<<" "; cout<<Endl; //topping up procedure//..... }//function Implementation//output The element value of the vector<string> array Object v in an iteratorvoidOutput2 (vector<string> &v) {vector<string>:: Iterator it; for(It=v.begin (); It!=v.end (); + +it) cout<<*it<<" "; cout<<Endl; //topping up procedure//..... }
6-17. The pointer does not point to a valid address
6-18. The pointer space is not released, resulting in waste
#include"book.h"#include<vector>#include<iostream>#include<cstring>using namespacestd;intmain () {vector<Book>Books; //defining a Vector<book> class object//topping up procedure// ... stringISBN, title; floatPrice ; while(cin>>isbn&&isbn!="EOF") {cin>>title>>Price ; Books.push_back (Book (isbn,title,price)); } //Enter the book information, construct the book object, and add to the previously defined Vector<book> class object//loop input until Ctrl + Z (you can also define your own input end mode)//topping up procedure// ... for(intj=0; J<books.size (); j + +) Books[j].print (); //output all book information in storage//topping up procedure// ... return 0;
C + + experiment Five