Hey guys, I've got a few programs that aren't running for different reasons.
Program 1:
It runs, and starts with the line This program shows five club member joining, then leaving, the club but then it freezes and the computer tries to debug the program itself, but then even that fails.Code://Debug 6-3 #include<iostream> #include<conio.h> using namespace std; class ClubMember { public: static int count; char name[20]; ClubMember(char* name); ~ClubMember(); }; int ClubMember::count = 0; ClubMember::ClubMember(char* name) { ++count; strcpy(name,name); cout<<"ClubMember #"<<count<<" created: "; cout<<name<<" has joined the club"<<endl; } ClubMember::~ClubMember() { --count; cout<<name<<" has left the club"<<endl; cout<<count<<" ClubMembers left"<<endl; } void main() { { cout<<"This program shows five club members"<<endl<<"joining, then leaving, the club"<<endl; ClubMember club[5] = {ClubMember("Jim"),ClubMember("Tom"),ClubMember("Julie"),ClubMember("Jane"),ClubMember("Kate")}; } std::cin.clear(); std::cin.ignore(); getchar(); }
Program 2:
Works fine, except instead of showing the cake flavor or frosting flavor it just shows a lot of piping.Code://Debug 6-2 #include<iostream> #include<conio.h> using namespace std; class BirthdayCake { public: //made entire class public int orderNumber; char cakeFlavor[20]; char frostingFlavor[20]; int numCandles; BirthdayCake(int num, char cake[], char frost[], int numCandles); //got rid of intialization of cake, frost and numCandles. Void added. void displayBirthdayCake(); }; BirthdayCake::BirthdayCake(int num, char cake[] = "white", char frost[] = "vanilla", int candles = 1) { orderNumber = num; cake = cakeFlavor; frost = frostingFlavor; numCandles = candles; } void BirthdayCake::displayBirthdayCake() { cout<<"Order #"<<orderNumber<<" "<<cakeFlavor<<" cake with "<< frostingFlavor<<" frosting and "<<numCandles; if(numCandles == 1) cout<<" candle"; else cout<<" candles"; cout<<endl; } void main() { cout<<"Cakes are white with vanilla frosting and 1 candle unless otherwise indicated. "<<endl; BirthdayCake a(111,"chocolate","chocolate",8); BirthdayCake b(222,"yellow", "chocolate"); BirthdayCake c(333,"banana"); BirthdayCake d(444); a.displayBirthdayCake(); b.displayBirthdayCake(); c.displayBirthdayCake(); d.displayBirthdayCake(); std::cin.clear(); std::cin.ignore(); getchar(); }
Program 3:
Runs, but it's supposed to put the name "Mike" for the mechanic when it's not already given and it just gives a blank. Originally I had it so that char name[] wasn't first, it was in the middle, but then I didn't have the empty quotations marks in void main() when it's giving the parameters for each car.Code://Chapter 6 Debug 1 #include<iostream> #include<conio.h> using namespace std; class Auto { public: int autoId; char mechanicName[20]; double fee; Auto(char name[], int id, double amt); //switched above line with Auto1 function, above line initialized variables and added void //also switched so char name[] was first void showAuto(); }; Auto::Auto(char name[], int id = 999, double amt = 25.00) // Valid, name (no default) comes before all others with default { autoId = id; strcpy(mechanicName, name); //this block switches the names passing to and from the functions fee = amt; } void Auto::showAuto() { cout<<"Auto #"<<autoId<<" worked on by "<<mechanicName<<" Amount due $"<<fee<<endl; //this function shows the information for each car } void main() { cout<<"Mike's Service "<<endl<<"Autos Worked on Today"<<endl<<endl; cout<<"Mike works on most cars. Occasionally he assigns a job to another mechanic"<<endl; cout<<"Minimum charge $25"<<endl<<endl; //the above 3 lines give the introduction to the program Auto car1(""), car2("", 321), car3("Amy", 456), car4("Jeremy", 567, 149); //provides the data for the function car1.showAuto(); car2.showAuto(); car3.showAuto(); car4.showAuto(); //the above 4 lines call the showAuto() function for each car std::cin.clear(); std::cin.ignore(); getchar(); }
Program 4:
"wool" by itself causing an error (no constructor available) and dressA.displayDress() is getting and error (under dressA) and it's saying Dress dressA() must have a class type.Code:// Debug 6-4 #include<iostream> #include<conio.h> using namespace std; class Dress { private: char material[20]; int size; char style[10]; double price; public: Dress(int sz, char mtrl[], char stl[]); void displayDress(); }; Dress::Dress(int sz, char mtrl[] = "cotton", char stl[] = "daytime") { strcpy(material,mtrl); sz = size; strcpy(style,stl); price = 29.99; if(strcmp(material,"silk") == 0) price += 20.00; if(strcmp(style, "evening")==0) price += 40.00; } void Dress::displayDress() { cout<<"A size "<<size<<" dress made of "<<material<<" and suitable for "<< style<<" wear costs $"<<price<<endl; } void main() { cout<<"Dress sale! $29.99. Only $20 more for" <<"sil. Only $40 more for evening designs."<<endl; Dress dressA(), dressB("wool"), dressC(14,"silk","evening"), dressD(4,"denim","casual"),dressE(8,"silk","business"); dressA.displayDress(); dressB.displayDress(); dressC.displayDress(); dressD.displayDress(); dressE.displayDress(); getch(); }



LinkBack URL
About LinkBacks



