1. Write a c++ program to create a vector of integers. copy the vector contents into list, sort the contents, then copy selected items into another vector(like elements less than 10 etc)
I know it would be easier to create an int array, but I want the program to create integers as the user requests. For example, if the user enters 4, the program creates 4 integers with the names input. Each integer is better as an individual integer, not an element in an array.I'm not sure if this is a possibility with C++.
I have a struct called Array and I'm to create a function to create a dynamic array that's fill with randomly generated integers from 0 to 50 (inclusive) and a function to destroy the array for freeing its memory. Below the code that I have written so far.
Code:
* Struct */ typedef struct {int *pArray; //the dynamic array int length; //the size of the dynamic array}Array; /* Function to create a dynamic array */ Array *initializeArray (int length) {int i; }
I need a program to run that will accept an input for user id. It will take the customer input and capitalize the letters, and return invalid id with the user inputted values. Then if it's valid it will add a counter counting the number of letters and numbers. It will keep track until the user puts in !. It seems when I try to pass values from the array to my toUpper function to capitalize it it doesn't seem to work right.
I am creating a WinForm registration application and my program accepts user input information and stores it but I am struggling to use my login function. I believe there is an error in the area of cmd.Parameters.AddWithValue section, I dont think addwithvalue is correct ? I get a fatal crash has occurred when I click Login
string constring = "datasource=127.0.0.1;port=3306;username=root;password=welcome"; string Query = "SELECT * FROM 'userinfo'.'users' where 'username' = @userid and 'password' = @password)"; MySqlConnection conDatabase = new MySqlConnection(constring); MySqlCommand cmd = new MySqlCommand(Query, conDatabase); cmd.Parameters.AddWithValue("@userid", this.userid_txt.Text); cmd.Parameters.AddWithValue("@passone", this.passone_txt.Text);
[code]....
Fixed the crash error, simple typo but now I am getting SQL Syntax errors which I originally believed I fixed.
#include <iostream> #include <iomanip> using namespace std;
// Function Prototype void sortArray(int array[], int size);
[Code] ....
This program was made to allow students to enter as many test scores as they want and the program will show them in ascending order and then will calculate the average of all test scores. It works wonderful until you enter a negative test score and then it throws the averaging process off. I can't seem to be able to make the program not accept the negative numbers.
Write a program that accepts a positive integer. The program should be the same from the given output. Use do while to allow the user to continue or not.
OUTPUT must be:
n = 5 0 1==0 2==1==0 3==2==1==0 4==3==2==1==0 5==4==3==2==1==0
if n = 6 0 1==0 2==1==0 3==2==1==0 4==3==2==1==0 5==4==3==2==1==0 6==5==4==3==2==1==0
I want to fix this code. The program must accept 7 values or stop it when you type s. The code not only couts the element, but also some other random numbers.
Code: #include<iostream> using namespace std; int main() { int numb[7]; int i; char s; for (i=0;i<=6;i++)
Write a program that reads four integers from a file ‘input.txt’.
The program will then create a single integer number from the four integers. The output of the program will be the single number and single number + 600.
#include <iostream> using namespace std; int main () { int number , a; cout<<"enter en integer number"; cin>>number; cout<<"add 600 to the number" cin>>a=number+600; return 0; }
Write a function named replaceSubstring. The function should accept three C-string or string object arguments.
Let's call them string1, string2, and string3. It should search string1 for all occurrences of string2. When it finds an occurrence of string2, it should replace it with string3.
For example, suppose the three arguments have the following values:
string1: "the dog jumped over the fence" string2: "the" string3: "that"
With these three arguments, the function would return a string object with the value "that dog jumped over that fence." Demonstrate the function in a complete program.
I am making a program which is going to print out a head image according to the input values entered by the user. Here is the code:
Code: #include <iostream> #include <string> using namespace std; void Sides() // draws the sides to take proportion
[Code] .....
At first i tried to work program like:
Code: cout << "plase enter which way you want to print out the head, with parted hair or bald." << endl; cin >> headstyle; if (headstyle != "bald" || headstyle != "parted hair" )
But it also had given the same mistake. The program compiles BUT; even if I put in the values bald or parted hair the program prints out "wrong input" then exits.
#include <iostream> #include <fstream> #include <cstdlib> #include <ctime> using namespace std; int main () { ofstream fout("datain.txt",ios::out); int array[6][6];
I compiled a simple program using a function to add two integers, in order to understand the difference of calling by value vs by reference.
Code:
#include <stdio.h> int add(int a, int b, int sum); int main() { int a, b, sum; printf("Please enter two integers "); scanf("%d%d", &a, &b);
[Code]...
I used these two (one, two) pages I found in the net while studying the subject. So here are my questions...
(a) Do I understand correctly that in the above code all a, b and sum are passed by value? (b) If I wanted only sum to be passed by reference, how the above code would change? (c) If I wanted all (a, b, sum) to be passed by reference, how the above code would change?
-Create three files namely all_numbers, odd_number and even_number. -Get the number of records and the numbers to store from the user. -Save all the numbers in "all_numbers" file. -Read each number and check whether it is odd or even. -Store the odd numbers in odd_number file and even numbers in even_number file. -Finally, print the numbers stored in odd_number and even_number files.
I created a program in C that opens a text file and read integers.
File `numbers.txt`: > 5 6 4 6 3 4 1
I use some restrictions with the `fscanf()` library and read the file, just for the record, and if everything goes fine I proceed to the next part of code (I know I could use `fget()`, but this is how I done it).The next part of the code will be this:
- First, I want the program to read the numbers from right to left. I look for an answer in google and many C courses, but I couldn't find a working solution. I think that the code is pretty simple, though I can't find it. **To be clear for the next part, we read the numbers from right to left.**
- Then, this is the hard part for me: I want the program to read the numbers and if the next number is higher (**not equal**) than the last one to keep it in memory, **only if it's higher than the last.** This can be continue for **1 through 500.000 numbers.**
- Then when the procedure done, I want to print how many numbers are greater than the last one and save it to a file, which I can do it if I solve the last problem.
We have the below numbers: 5 6 4 6 3 4 1
The program starts to read the numbers from right to left.Now which and how many numbers are greater than the last one?
The answer is 3 numbers: 5 6 4 [6] 3 [4] [1]
Then the program will print the number 3 with a message and save it to a file called `xxx.txt`. I am posting the `main` code, not all the code just what you need to solve the problem:
Code:
#include <errno.h> // macros for reporting and retrieving error conditions #include <stdio.h> // load main C library function #include <stdlib.h> // need that for many reasons ;) #include <string.h> // loads various of characters functions }
[code]....
In conclusion, I want 2 pieces of code:
- One to read the numbers from right to left - One to make the above procedure
Add a program that declares two arrays of 5 integers each. Provide one function to load one array with random numbers from 1 to 25, another to fill the other array with user supplied values, and a third function to print an array. The main function should declare the arrays and use the functions to fill each array and print them both.
The code i have so far is #include <cstdlib> #include <iostream> using namespace std; void printaaray(int printarray1[], int printarray2);
I have done some programming or rather have written and implemented some algorithms in code (is there a difference? :-)) but am having some teething problems with a project I am currently working on.
To start with I am simply reading in the data from a .txt file into a vector. This is the code that I currently have:
This compiles fine but currently outputs a different integer everytime I run the program. I can remember having this problem when I started coding before using a different language and if I remember correctly it was quite easy to resolve. I thought it was because I had missed off the 'return 0' but it is something similar I think.
I want to pass some strings and int values from a file to my program.. if i was using c i could do it like
scanf(p,"%s %s %d %d",&str1,&str2,&num1,&num2);
I don't want to get the whole line just the values one by one if i wanted the whole line i could do it with getline(); now that i want the values one by one how do i do it ...