المشكلة في الكود انه لا يظهر الuser input لكن يظهر كل شيء تاني. ايش ممكن تكون المشكلة؟
The header file
#ifndef BOOKTYPE_H
#define BOOKTYPE_H
#include<iostream>#include<string>usingnamespace std;class bookType
{public:// constructor
bookType();
bookType(string title ,int noOfAuthors,
string authors[4], string publisher,int ISBN,double price,int noOfCopies);// functionsvoid setTitle(string t);// sets title
string getTitle()const;// returns titlevoid showTitle();// shows titlevoid setNoOfAuthors(int numA);// sets no of authorsint getNoOfAuthors();// returns no of authorsvoid showNoOfAuthors();// shows no of authorsvoid setAuthors(string authors[4]);// sets authors array
string getAuthors()const;// returns authorsvoid showAuthors();// shows authorsvoid setPublisher(string pblshr);// sets publisher
string getPublisher()const;// returns publishervoid showPublisher();// shows publishervoid setISBN(int isbn);// sets isbnint getISBN()const;// returns isbnvoid showISBN();// shows isbnvoid setPrice(int pr);// sets pricedouble getPrice()const;// returns pricevoid showPrice();// shows pricevoid setCopies(int numC);// sets no of copiesint getCopies()const;// returns no of copiesvoid showCopies();// shows no of copiesvoid printBookInfo();// prints books informationvoid updateNoOfCopies(int n);// updates no of copies of booksvoid search(char respnse);// searches by title or ISBNprivate:// attributes
string title, authors[4], publisher;int ISBN, noOfCopies, noOfAuthors, var, n;double price;char response;};#endif// BOOKTYPE_H
The cpp file
#include"bookType.h"
bookType::bookType(){
title ="";
noOfAuthors =0;
authors[0]="";
authors[1]="";
authors[2]="";
authors[3]="";
publisher ="";
ISBN =0;
price =0.0;
noOfCopies =0;}
bookType::bookType(string title,int noOfAuthors,
string authors[4], string publisher,int ISBN,double price,int noOfCopies){
title ="";
noOfAuthors =0;
authors[0]="";
authors[1]="";
authors[2]="";
authors[3]="";
publisher ="";
ISBN =0;
price =0.0;
noOfCopies =0;}// end constructor
bookType books[5];void bookType::setTitle(string t){
title = t;}
string bookType::getTitle()const{return title;}void bookType::showTitle(){
cout <<"\nTitle: ";
cout << title;}void bookType::setNoOfAuthors(int numA){if(numA >=0){
noOfAuthors = numA;}else
noOfAuthors =0;}int bookType::getNoOfAuthors(){return noOfAuthors;}void bookType::showNoOfAuthors(){
cout <<"\nNumber of Authors: "<< noOfAuthors << endl;}void bookType::setAuthors(string authors[4]){for(int i =0; i <4; i++){
cout <<"\nAuthor "<< i +1<<": ";
cin >> authors[i];}// end for}
string bookType::getAuthors()const{//return authorName;for(int i =0; i <4; i++){return authors[i];}}void bookType::showAuthors(){
cout <<"\nAuthor(s)";if(authors[0]!="")
cout << authors[0];if(authors[1]!="")
cout <<", "<< authors[1];if(authors[2]!="")
cout <<", "<< authors[2];if(authors[3]!="")
cout <<", "<< authors[3];
cout << endl;}void bookType::setPublisher(string pblshr){
publisher = pblshr;}
string bookType::getPublisher()const{return publisher;}void bookType::showPublisher(){
cout <<"\nPublisher: ";
cout << publisher;}void bookType::setISBN(int isbn){
ISBN = isbn;}int bookType::getISBN()const{return ISBN;}void bookType::showISBN(){
cout <<"\nISBN: ";
cout << ISBN;}void bookType::setPrice(int pr){if(pr >=0){
price = pr;}else
price =0;}double bookType::getPrice()const{return price;}void bookType::showPrice(){
cout <<"\nPrice: ";
cout << price;}void bookType::setCopies(int numC){if(numC >=0){
noOfCopies = numC;}else
noOfCopies =0;}int bookType::getCopies()const{return noOfCopies;}void bookType::showCopies(){
cout <<"\nNumber of Copies: ";
cout << noOfCopies;}void bookType::printBookInfo(){ showTitle();
showNoOfAuthors();
showAuthors();
showPublisher();
showISBN();
showPrice();
showCopies();}// end printBookInfovoid bookType::updateNoOfCopies(int n){
n = noOfCopies;}void bookType::search(char response)// searches by title or ISBN{if(response =='y'){
cout <<"Enter 1 to search by title or 2 by ISBN: ";
cin >> var;switch(var){case1:{
cout <<"Enter book title: ";
string newTitle;
cin >> newTitle;for(int j =0; j <5; j++){
string temp = books[j].getTitle();if(newTitle == temp){
books[j].printBookInfo();}// end if}// end for loopbreak;}// end case1case2:{
cout <<"Enter book ISBN: ";int newISBN;
cin >> newISBN;for(int i =0; i <5; i++){int temp = books[i].getISBN();if(newISBN = temp){
books[i].printBookInfo();}// end if}// end for loopbreak;}// end case2default:{
cout <<"Invalid Input!";}// end default}// end switch}// end ifelse
cout <<"Thank you!";}// end search
The main file
#include<iostream>#include"bookType.h"int main(){
cout <<"\nThis program prints books information.";// attributes
string title, authors[4], publisher, authorName;int ISBN, noOfCopies, noOfAuthors;double price;char response;
bookType books[5];for(int i =0; i<2; i++){
cout <<"\n*********************************";
cout <<"\nEnter book title: ";
cin >> title;// reads title
cout <<"\nEnter number of authors(1-4): ";
cin >> noOfAuthors;// reads noOfAuthors
cout <<"\nEnter name(s) of authors: ";for(int i =0; i < noOfAuthors; i++){
cout <<"Author "<< i +1<<": ";
cin >> authors[i];}// end for
cout <<"\nEnter book publisher: ";
cin >> publisher;// reads publisher
cout <<"\nEnter book ISBN: ";
cin >> ISBN;// reads ISBN
cout <<"\nEnter book price: ";
cin >> price;// reads price
cout <<"\nEnter number of book copies: ";
cin >> noOfCopies;// reads noOfCopies
bookType b(title, noOfAuthors, authors, publisher, ISBN, price, noOfCopies);
books[i]= b;}
cout <<"\nBooks information is displayed below.";for(int j =0; j<2; j++){
books[j].printBookInfo();
cout <<"\n***************";}
bookType b1;
cout <<"\nWould you like to search for a book ?";
cout <<"Enter y for yes and n for no: ";
cin >> response;
b1.search(response);return0;}
Input:
This program prints books information.
*********************************
Enter book title: sth
Enter number of authors(1-4): 1
Enter name(s) of authors: Author 1: hh
Enter book publisher: aa
Enter book ISBN: 111
Enter book price: 11
Enter number of book copies: 1
*********************************
Enter book title: sth1
Enter number of authors(1-4): 1
Enter name(s) of authors: Author 1: aa
Enter book publisher: aa
Enter book ISBN: 111
Enter book price: 11
Enter number of book copies: 1
Output:
Books information is displayed below.
Title:
Number of Authors: 14703328
(Author(s
Publisher:
ISBN: 1023
Price: 1.63536e-321
Number of Copies: 0
***************
Title:
Number of Authors: 14703328
Author(s)
Publisher:
ISBN: 1023
Price: 1.63536e-321
Number of Copies: 0
السؤال
Hala Haneya
السلام عليكم ..
المشكلة في الكود انه لا يظهر الuser input لكن يظهر كل شيء تاني. ايش ممكن تكون المشكلة؟
The header file
The cpp file
The main file
Input:
This program prints books information.
*********************************
Enter book title: sth
Enter number of authors(1-4): 1
Enter name(s) of authors: Author 1: hh
Enter book publisher: aa
Enter book ISBN: 111
Enter book price: 11
Enter number of book copies: 1
*********************************
Enter book title: sth1
Enter number of authors(1-4): 1
Enter name(s) of authors: Author 1: aa
Enter book publisher: aa
Enter book ISBN: 111
Enter book price: 11
Enter number of book copies: 1
Output:
Books information is displayed below.
Title:
Number of Authors: 14703328
(Author(s
Publisher:
ISBN: 1023
Price: 1.63536e-321
Number of Copies: 0
***************
Title:
Number of Authors: 14703328
Author(s)
Publisher:
تم التعديل في بواسطة Hala HaneyaISBN: 1023
Price: 1.63536e-321
Number of Copies: 0
1 جواب على هذا السؤال
Recommended Posts
انضم إلى النقاش
يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.