I need to now how to input the following code into the complier for C++ code. It is for chapter 8 question 7a in the PLD book
// Start
// Declarations
// num MAXADS = 100
// num adcatcode[MAXADS]
// num adwords[MAXADS]
// num curCode
// num numads
// num i
// num j
// num k
// num subtotal
// num temp
// output "Please enter the number of ads: "
// input numads
// if ((numads > 0) and (numads <= MAXADS))
// for i = 0 to numads - 1
// output "Please enter Advertisement Category Code (1 - 15): "
// input adcatcode[i]
// output "Please enter number of words for the advertisement: "
// input adwords[i]
// endfor
// for i = 0 to numads - 2
// for j = 0 to numads - 2
// if (adcatcode[j] > adcatcode[j+1])
// temp = adcatcode[j]
// adcatcode[j] = adcatcode[j+1]
// adcatcode[j+1] = temp
// temp = adwords[j]
// adwords[j] = adwords[j+1]
// adwords[j+1] = temp
// endif
// endfor
// endfor
// output "Total Word Counts Sorted By Category Code"
// output "========================================="
// k = 0
// while k <= numads - 1
// subtotal = 0
// curCode = adcatcode[k]
// while ( (curCode = adcatcode[k]) and (k <= numads - 1) )
// subtotal = subtotal + adwords[k]
// k = k + 1
// endwhile
// output "Category: ",adcatcode[k - 1], " ","Word Count: ", subtotal
// endwhile
// else
// output "Number adds requested less than 1 or is too large; ad limit is ", MAXADS
// endif
// Stop
Copyable code:
//Include the files
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
//main
int main()
{
//Declare MAXADS
const int MAXADS = 100;
//Declare
int adcatcode[MAXADS];
int adwords[MAXADS];
int curCode;
int numads;
int i;
int j;
int k;
int subtotal;
int temp;
//Get value numads
cout<<"Please enter the number of ads:";
cin>>numads;
//Check condition
if((numads>0) && (numads<=MAXADS))
{
//For loop
for(i=0;i<numads;i++)
{
//get advertisement code
cout<<"Please enter Advertisement Category Code(1-15):";
cin>>adcatcode[i];
//Get words
cout<<"Please enter number of words for the advertisement:";
cin>>adwords[i];
}
//Outer for loop
for(i=0;i<numads-1;i++)
{
//Inner for loop
for(j=0;j<numads-1;j++)
{
//CHeck condition
if(adcatcode[j]>adcatcode[j+1])
{
//Swap advertisement code
temp=adcatcode[j];
adcatcode[j]=adcatcode[j+1];
adcatcode[j+1]=temp;
//swap words
temp=adwords[j];
adwords[j]=adwords[j+1];
adwords[j+1]=temp;
}
}
}
//Display message
cout<<"Total Word Counts Sorted By Category Code"<<endl;
cout<<"============================================"<<endl;
k=0;
//Loop
while(k<=numads-1)
{
subtotal=0;
curCode=adcatcode[k];
//Loop
while((curCode==adcatcode[k]) && (k<=numads-1))
{
subtotal = subtotal + adwords[k];
k=k+1;
}
//Display
cout<<"Category:"<<adcatcode[k-1]<<" , Word Count:"<<subtotal<<endl;
}
}
//If not valid value for numads
else
//Display message
cout<<"Number adds requested less than 1 or is too large; ad limit is "<< MAXADS<<endl;
//Return
return 0;
}
I need to now how to input the following code into the complier for C++ code....
Find Bugs in the pseudocode// A high school is holding a recycling competition// This program allows a user to enter a student's // year in school (1 through 4)// and number of cans collected// Data is entered continuously until the user wnats to quit// After headings, output is four lines// one for each school year classstart Declarations num year num cans num SIZE = 4 num QUIT = 9 ...
Turning this Pseudocode into the described C++ Program? (will include Pseudocode AND Description of the Program below!) Pseudoode: start Declarations num deptNum num salary num hrsWorked num SIZE = 7 num totalGross[SIZE] = 0 string DEPTS[SIZE] = “Personnel”, “Marketing”, “Manufacturing”, “Computer Services”, “Sales”, “Accounting”, “Shipping” getReady() while not eof detailLoop() endwhile finishUp() stop getReady() output “Enter the department number, hourly salary, and number of hours worked” input deptNum, salary, hrsWorked return detailLoop() if deptNum >= 1 AND deptNum...
Please I need help debugging this code thanks. // The two senior class homerooms at Littleville High School // are having a fundraising drive for the prom. Each time a student // solicits a contribution, a record is created with the // student's name and the value. Two files have been created for // Homeroom A and Homeroom B. Each file is sorted in contribution // value order from highest to lowest. This program merges the two files. start ...
Please code this in C++: // Start // Declarations // number currentTuition // number futureTuition // number interestRate // number numYears // number year // // output "Please enter current tuition: " // input currentTuition // output "Please enter interest rate (e.g. 9.0 for 9 percent): " // input interestRate // output "Please number of years for tuition: " // input numYears // output “Tuition at year 1 is “, currentTuition // // futureTuition = currentTuition // for year =...
C++ problem where should I do overflow part? in this code do not write a new code for me please /////////////////// // this program read two number from the user // and display the sum of the number #include <iostream> #include <string> using namespace std; const int MAX_DIGITS = 10; //10 digits void input_number(char num[MAX_DIGITS]); void output_number(char num[MAX_DIGITS]); void add(char num1[MAX_DIGITS], char num2[MAX_DIGITS], char result[MAX_DIGITS], int &base); int main() { // declare the array = {'0'} char num1[MAX_DIGITS] ={'0'}; char...
// This application reads sales data for a real estate broker. // The user enters a record for each of 10 salespeople // containing the salesperson's name, // the number of properties sold by that person during the month, // and the total value of those properties. // The data records are sorted by value so the data for // the top three salespeople can be displayed. // Modify the program to // (1) enter data for any number of...
C++
how can I fix these errors
this is my code
main.cpp
#include "SpecialArray.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int measureElementsPerLine(ifstream& inFile) {
// Add your code here.
string line;
getline(inFile, line);
int sp = 0;
for (int i = 0; i < line.size(); i++)
{
if (line[i] == ' ')
sp++;
}
sp++;
return sp;
}
int measureLines(ifstream& inFile) {
// Add your code here.
string line;
int n = 0;
while (!inFile.eof())
{
getline(inFile,...
I need to add a for or a while loop to the following code. please help needs to be in c++. #include <iostream> #include <string.h> using namespace std; int main() { char input[100]; cout << "Please enter a character string: "; cin >> input; char *head = &input[0], *tail = &input[strlen(input) - 1]; char temp = *head; *head = *tail; *tail = temp; tail--; head++; cout << "CString = " << input << "\n"; }
The following code is a Java code for insertion sort. I would like this code to be modified by not allowing more than 10 numbers of integer elements (if the user enters 11 or a higher number, an error should appear) and also finding the range of the elements after sorting. /* * Java Program to Implement Insertion Sort */ import java.util.Scanner; /* Class InsertionSort */ public class InsertionSortTwo { /* Insertion Sort function */ public static void sort( int...
Please can someone help me correct this code? def newton(num): temp = 0.000001 estimate = 1.0 while True: estimate = (estimate + num / estimate) / 2 difference = abs(num - estimate ** 2) if difference <= temp: break return estimate def main(): while True: try: num = int(input("Enter a positive number or enter/return to quit: ")) print("newton = %0.15f" % newton(num)) except: return main()