Click here to Skip to main content
14,574,365 members

Managed C++/CLI

 
PinnedThe C++ / CLI is for managed and mixed-mode C++ programming only Pin
Chris Maunder9-Jan-06 9:36
cofounderChris Maunder9-Jan-06 9:36 
Questionc++ program Pin
Member 148568768-Jun-20 2:31
MemberMember 148568768-Jun-20 2:31 
AnswerRe: c++ program Pin
Eddy Vluggen8-Jun-20 3:01
professionalEddy Vluggen8-Jun-20 3:01 
GeneralRe: c++ program Pin
Member 148568768-Jun-20 4:27
MemberMember 148568768-Jun-20 4:27 
GeneralRe: c++ program Pin
Eddy Vluggen8-Jun-20 5:13
professionalEddy Vluggen8-Jun-20 5:13 
GeneralRe: c++ program Pin
Member 148568768-Jun-20 5:23
MemberMember 148568768-Jun-20 5:23 
GeneralRe: c++ program Pin
Richard MacCutchan8-Jun-20 5:34
mveRichard MacCutchan8-Jun-20 5:34 
GeneralRe: c++ program Pin
Member 148568768-Jun-20 5:51
MemberMember 148568768-Jun-20 5:51 
GeneralRe: c++ program Pin
Richard MacCutchan8-Jun-20 6:00
mveRichard MacCutchan8-Jun-20 6:00 
GeneralRe: c++ program Pin
Member 148568768-Jun-20 6:26
MemberMember 148568768-Jun-20 6:26 
GeneralRe: c++ program Pin
Richard MacCutchan8-Jun-20 6:38
mveRichard MacCutchan8-Jun-20 6:38 
GeneralRe: c++ program Pin
Eddy Vluggen8-Jun-20 8:31
professionalEddy Vluggen8-Jun-20 8:31 
GeneralRe: c++ program Pin
Member 148568768-Jun-20 8:46
MemberMember 148568768-Jun-20 8:46 
GeneralRe: c++ program Pin
Eddy Vluggen8-Jun-20 8:50
professionalEddy Vluggen8-Jun-20 8:50 
GeneralRe: c++ program Pin
Member 148568768-Jun-20 9:01
MemberMember 148568768-Jun-20 9:01 
Task1:
Write a program in C++ that reads data from a file (ask user to enter file name). The number of elements in file are unknown so, you are supposed to regrow the array and dynamically allocate the memory every time it is needed.
Now, your task is to keep asking user two numbers, one is a num and second is location. Insert the num into that location and move the other elements to the right by re growing the array whenever needed. The function should keep asking user the number and location until user enters -99 in num.

Make sure to make independent function for different functionalities.

Example
Data: 2 3 15 1 82 8 9 10 21 55 12 14 16 18
Number = 74, Location = 3
Updated Data: 2 3 74 15 1 82 8 9 10 21 55 12 14 16 18
Number = -22, Location =5
Updated Data: 2 3 74 15 -22 1 82 8 9 10 21 55 12 14 16 18
Number = -99
Program Ended
My solution:

include<iostream>

include<conio.h>

include<fstream>


int main()
{
int arr[50], size, insert, i, pos;
std::cout<<"Enter  Size : ";
std::cin>>size;
std::cout<<"Data : ";
for(i=0; i<size; i++)
{
    std::cin>>arr[i];
}
std::cout<<"Number : ";
std::cin>>insert;
std::cout<<"Location : ";
std::cin>>pos;

for(i=size; i>pos; i--)
{
    arr[i]=arr[i-1];
}

arr[pos]=insert;
std::cout<<"Updated Data";

for(i=0; i<size+1; i++)
{
    std::cout<<arr[i]<<" ";
}

return 0;

}

My problem regarding this solution=1. i am unable to stoop the program when i enter -99 i tires to put condition in different positions but i failed..
2. i am unable to keep asking user number and location
GeneralRe: c++ program Pin
Member 148568768-Jun-20 9:09
MemberMember 148568768-Jun-20 9:09 
GeneralRe: c++ program Pin
Richard MacCutchan10-Jun-20 5:19
mveRichard MacCutchan10-Jun-20 5:19 
GeneralRe: c++ program Pin
Eddy Vluggen10-Jun-20 4:11
professionalEddy Vluggen10-Jun-20 4:11 
QuestionStrings in C | The program gives wrong output on string composed of both Upper case and lower case (Logic : ASCII Comparision) Why? Pin
Member 148492461-Jun-20 2:37
MemberMember 148492461-Jun-20 2:37 
AnswerRe: Strings in C | The program gives wrong output on string composed of both Upper case and lower case (Logic : ASCII Comparision) Why? Pin
Richard MacCutchan1-Jun-20 3:15
mveRichard MacCutchan1-Jun-20 3:15 
GeneralRe: Strings in C | The program gives wrong output on string composed of both Upper case and lower case (Logic : ASCII Comparision) Why? Pin
k50541-Jun-20 4:22
mvek50541-Jun-20 4:22 
GeneralRe: Strings in C | The program gives wrong output on string composed of both Upper case and lower case (Logic : ASCII Comparision) Why? Pin
Richard MacCutchan1-Jun-20 5:05
mveRichard MacCutchan1-Jun-20 5:05 
GeneralRe: Strings in C | The program gives wrong output on string composed of both Upper case and lower case (Logic : ASCII Comparision) Why? Pin
Member 79891221-Jun-20 7:25
MemberMember 79891221-Jun-20 7:25 
GeneralRe: Strings in C | The program gives wrong output on string composed of both Upper case and lower case (Logic : ASCII Comparision) Why? Pin
Richard MacCutchan1-Jun-20 9:28
mveRichard MacCutchan1-Jun-20 9:28 
QuestionRun executable with arguments Pin
Erich Ruth3-May-20 3:04
MemberErich Ruth3-May-20 3:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.