C + + experiment Five

Source: Internet
Author: User

#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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.